Android中增加seekbar可觸控的區域
阿新 • • 發佈:2019-01-25
//mCurrentView 是Seekbar的父親
private void enlargeSeekBar(){
mCurrentView.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
Rect seekRect = new Rect();
mSeekBar.getHitRect(seekRect);
if((event.getY() >= (seekRect.top-50)) && (event.getY()<= (seekRect.bottom+50))){
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 mSeekBar.onTouchEvent(me);
}
return false;
}
});
}