Tôi có lớp sau đại diện cho Chế độ xem có thể chạm và vẽ Thanh trượt.ACTION_CANCEL khi chạm vào
public class SlideBar extends View {
private int progress;
private int max;
private Paint background;
private Paint upground;
private RectF bar;
private boolean firstDraw;
public SlideBar(Context context, AttributeSet attrs) {
super(context, attrs);
progress = 0;
upground = new Paint();
upground.setColor(Color.parseColor("#C2296C"));
background = new Paint();
background.setColor(Color.parseColor("#777777"));
}
private void onFirstDraw() {
max = getWidth();
bar = new RectF(0, 19, max, 21);
}
public void onDraw(Canvas canvas) {
if (!firstDraw) {
onFirstDraw();
progress = max;
firstDraw = true;
}
canvas.save();
canvas.drawRoundRect(bar, 5, 5, background);
canvas.drawCircle(progress, 20, 9, upground);
canvas.restore();
}
public void setValue(int value) {
progress = value;
}
public boolean onTouchEvent(MotionEvent evt) {
System.out.println(evt.getAction());
progress = (int) evt.getX();
invalidate();
return false;
}
}
Nhưng khi chạm và kéo nó, tôi nhận được ACTION_DOWN, một số ACTION_MOVE sau đó nhận được ACTION_CANCEL và không có sự kiện nào khác.
Tại sao điều đó xảy ra? Tôi không muốn hủy sự kiện và cho phép nó tiếp tục kéo thanh.
tôi nhận ra rằng điều này chỉ xảy ra khi thêm thành phần này vào một PopupWindow, làm thế nào tôi có thể đánh chặn các sự kiện và làm cho tất cả chúng đi đến con của nó? –
Tôi nhận ra đó là một HorizontalScrollView đang nắm lấy các sự kiện của tôi. –
https://www.youtube.com/watch?v=EZAoJU-nUyI điều này có thể hữu ích – kouretinho