Seekbar扩大点击区域

//扩大点击区域
private void enlargeSeekBar() {
mContentView.setOnTouchListener(new OnTouchListener() {//mContentView是mProgressSeekBar的父view

@Override
public boolean onTouch(View v, MotionEvent event) {
Rect seekRect = new Rect();
mProgressSeekBar.getHitRect(seekRect);

if ((event.getY() >= (seekRect.top - 100)) && (event.getY() <= (seekRect.bottom + 100))
&& event.getX() >= seekRect.left && event.getX() <= seekRect.right) {

float y = seekRect.top + seekRect.height() / 2;
float x = event.getX() - seekRect.left;//seekBar只接受相对x位置
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 mProgressSeekBar.onTouchEvent(me);

}
return false;
}
});
}

posted on 2016-11-30 16:54  guangdeshishe  阅读(844)  评论(0编辑  收藏  举报

导航