2 baidu 36399370 baidu_36399370 于 2017.01.10 13:51 提问

安卓自定义seekbar FromUser始终为false

public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public VerticalSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public VerticalSeekBar(Context context) {
    super(context);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(h, w, oldh, oldw);
}

@Override
protected synchronized void onDraw(Canvas canvas) {
    canvas.rotate(-90);
    canvas.translate(-getHeight(), 0);
    super.onDraw(canvas);
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec,
        int heightMeasureSpec) {
    super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth() + 100);
}

@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;
}

// 解决调用setProgress()方法时滑块不跟随的bug
@Override
public synchronized void setProgress(int progress) {
    super.setProgress(progress);
    onSizeChanged(getWidth(), getHeight(), 0, 0);
}

1个回答

YXTS122
YXTS122   2017.01.10 15:49

始终为false?无图无真相

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!