가로 목록보기에서 세로 탐색 막대를 사용하고 있는데 현재 탐색 막대는 진행률 드로어 블에서 손가락 터치로도 움직입니다. 하지만 엄지가 움직일 때만 움직이고 싶어요. progressdrawable을 터치하면 탐색 막대 값이 변경되지 않아야합니다. 어떻게 예방할 수 있습니까?
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);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(),0);
super.onDraw(c);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
int i=0;
i=getMax() - (int) (getMax() * event.getY() / getHeight());
setProgress(i);
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
Drawable mThumb;
@Override
public void setThumb(Drawable thumb) {
super.setThumb(thumb);
mThumb = thumb;
}
public Drawable getSeekBarThumb() {
return mThumb;
}
public void updateThumb(){
onSizeChanged(getWidth(), getHeight(), 0, 0);
}}
다음과 같이 문제를 해결했습니다. 엄지 이미지 바깥 쪽을 터치하면 탐색 막대 값이 변경되지 않습니다.
holder.vertical_seekBar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE ||
event.getAction() == MotionEvent.ACTION_UP ||
event.getAction() == MotionEvent.ACTION_DOWN){
Rect seekBarThumbRect = holder.vertical_seekBar.getSeekBarThumb().getBounds();
int seekBarHeight = holder.vertical_seekBar.getHeight();
if(seekBarThumbRect.left - (seekBarThumbRect.right - seekBarThumbRect.left) / 2 < (Math.abs(seekBarHeight - event.getY())) &&
seekBarThumbRect.right + (seekBarThumbRect.right - seekBarThumbRect.left) / 2 > (Math.abs(seekBarHeight - event.getY())) &&
seekBarThumbRect.top < event.getX() &&
seekBarThumbRect.bottom > event.getX())
return false;
}
return true;
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다