ACTION_CANCEL在触摸ACTION_CANCEL

由网友(坐在坟前调戏鬼)分享简介:我有一个重新$ P $下面的类psents一种观点认为是触摸并绘制一个滑动条。I has the following class that represents a View that is touchable and draw a Slide Bar.public class SlideBar extends V...

我有一个重新$ P $下面的类psents一种观点认为是触摸并绘制一个滑动条。

I has the following class that represents a View that is touchable and draw a Slide Bar.

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;
}
}

但接触并拖动它的时候,我收到了ACTION_DOWN,一些ACTION_MOVEs然后收到一个ACTION_CANCEL并没有进一步的活动。

But when touching and dragging it, I receive a ACTION_DOWN, some ACTION_MOVEs then receive a ACTION_CANCEL and no further events.

它为什么会发生?我不想取消该事件,并使其能够继续拖着吧。

Why it's happens? I don't want to cancel the event and enable it to keep dragging bar.

推荐答案

在父视图接管了其子视图之一的控制的ACTION_CANCEL发生。

An ACTION_CANCEL happens when a parent view takes over control of one of its children views.

看看文档周围ViewGroup.onInterceptTouchEvent(MotionEvent)方法。从链接:

Take a look at the documentation around ViewGroup.onInterceptTouchEvent(MotionEvent) method. From the link:

您将在这里收到按下事件。 在向下事件将被处理,或者通过该视图组的孩子,或者给自己的onTouchEvent()方法来处理;这意味着你应该实现的onTouchEvent()返回真,所以你会继续看到手势的其余部分(而不是寻找一个父视图来处理它)。此外,通过从的onTouchEvent()返回true,您将不会收到在onInterceptTouchEvent)以下任何事件(和所有触摸的处理必须的onTouchEvent()像正常的情况发生。 对于只要从该函数中,每个下面的事件中返回(直至并包括最后向上)假将首先注册,然后传送到目标的的onTouchEvent()。 如果你从这里返回true,您将不会收到任何下列事件:目标视图将收到相同的事件,而是用行动ACTION_CANCEL,以及接下来的所有事件将被传递到您的onTouchEvent()方法,并不再出现在这里
阅读全文

相关推荐

最新文章