【问题标题】:Vertical Seekbar popup at thumb. Popup misplace拇指处的垂直搜索栏弹出窗口。弹出错误位置
【发布时间】:2015-08-02 13:13:21
【问题描述】:

我正在开发一个应用程序,我同时使用水平和垂直搜索栏,并在拇指位置显示弹出窗口。

  1. 对于水平搜索栏,两者都很好。

  2. 但是当我们将搜索栏旋转 -90/270 度时,弹出窗口没有显示在正确的位置(拇指上方)

  3. 问题是我们尝试获取垂直位置的 Seekbar 拇指的边界,但我得到了水平位置的边界。

任何帮助都是可观的。

【问题讨论】:

    标签: android popup android-seekbar android-vertical-seekbar


    【解决方案1】:
        Try this vertical seekbar. As you see in **setProgress(int progress)** method thumb position will update, automatically. Good
     luck
    
    import android.content.Context;
        import android.graphics.Canvas;
        import android.util.AttributeSet;
        import android.view.MotionEvent;
        import android.widget.SeekBar;
    
        public class VerticalSeekBar extends SeekBar {
    
            public VerticalSeekBar(Context context) {
                super(context);
            }
    
            public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
            }
    
            public VerticalSeekBar(Context context, AttributeSet attrs) {
                super(context, attrs);
            }
    
            @Override
            public void onSizeChanged(int w, int h, int oldw, int oldh) {
                super.onSizeChanged(h, w, oldh, oldw);
            }
    
            @Override
            protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(heightMeasureSpec, widthMeasureSpec);
                setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
            }
    
            @Override
            protected void onDraw(Canvas c) {
                c.rotate(-90);
                c.translate(-getHeight(), 0);
    
                super.onDraw(c);
            }
    
            @Override
            public boolean onTouchEvent(MotionEvent event) {
                if (!isEnabled()) {
                    return false;
                }
    
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN :
                    case MotionEvent.ACTION_MOVE :
                    case MotionEvent.ACTION_UP :
                        setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
                        onSizeChanged(getWidth(), getHeight(), 0, 0);
                        break;
    
                    case MotionEvent.ACTION_CANCEL :
                        break;
                }
                return true;
            }
    
            @Override
            public synchronized void setProgress(int progress) {
                super.setProgress(progress);
                onSizeChanged(getWidth(), getHeight(), 0, 0);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      相关资源
      最近更新 更多