android seekbar怎么调触控范围
1个回答
展开全部
//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;
}
});
}
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;
}
});
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询