垂直Seekbar弹出拇指。弹出错位

时间:2015-05-21 03:34:03

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

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

  1. 对于水平搜索栏,情况都很好。

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

  3. 问题是我们试图将Seekbar拇指绑定到垂直位置,但我正处于水平位置的束缚。

  4. 任何帮助都很明显。

1 个答案:

答案 0 :(得分: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);
        }
    }