Another idea is to change the X and Y coordinates of the MotionEvent and pass them to the super implementation:
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 boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; } float x = (getHeight() - event.getY()) * getWidth() / getHeight(); float y = event.getX(); MotionEvent verticalEvent = MotionEvent .obtain(event.getDownTime(), event.getEventTime(), event.getAction(), x, y, event.getPressure(), event.getSize(), event.getMetaState(), event.getYPrecision(), event.getXPrecision(), event.getDeviceId(), event.getEdgeFlags()); return super.onTouchEvent(verticalEvent); } protected void onDraw(Canvas c) { c.rotate(-90); c.translate(-getHeight(), 0); super.onDraw(c); } @Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(heightMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); } protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(h, w, oldh, oldw); } }
In this case, there is no need to call the setProgress (int) method, and therefore you can use the boolean-flag "fromUser" in OnSeekBarChangeListener.onProgressChanged () to determine if the search was created by user interaction.
Christopher Dec 17 '13 at 11:52 2013-12-17 11:52
source share