SeekBar有时候太细了,触摸不到,找了个办法,做个笔记。
直接上代码:
seekbar_parent为seekBar外层布局,注:seekBar触摸区域与seekbar_parent的区域大小有关
seekbar_parent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Rect seekRect = new Rect();
seekBar.getHitRect(seekRect);
if ((event.getY() >= (seekRect.top - 500)) && (event.getY() <= (seekRect.bottom + 500))) {
float y = seekRect.top + seekRect.height() / 2;
//seekBar only accept relative x
float x = event.getX() - seekRect.left;
if (x < 0) {
x = 0;
} else if (x > seekRect.width()) {
x = seekRect.width();
}
MotionEvent me = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
event.getAction(), x, y, event.getMetaState());
return seekBar.onTouchEvent(me);
}
return false;
}
});