本文介绍了我如何与QUOT;重启"在Android的触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的查看,我重写 onTouchEvent(MotionEvent)。我作为文章的意识。我遇到的问题是,这个观点是在图库,需要触摸事件滚动最终使用。我已经添加了逻辑来检测时,我的观点已经完全滚动到左/右和返回false,但我认为图库需要完整的 MotionEvent ,以滚动的议案。这里就是我返回false:

I have a custom View and I'm overriding onTouchEvent(MotionEvent). I've implemented pinch-zoom in this view as described in the article Making Sense of Multitouch. The issue I'm having is that this view is ultimately used in a Gallery which needs touch events for scrolling. I've added logic to detect when my view has fully scrolled to the right/left and return false, but I think the Gallery needs the full MotionEvent motion in order to scroll. Here's where I return false:

case MotionEvent.ACTION_MOVE: {
    final int pointerIndex = event.findPointerIndex( getActivePointerId() );
    final float x = event.getX( pointerIndex );
    final float y = event.getY( pointerIndex );

    // Only move if the ScaleGestureDetector isn't processing a gesture.
    if ( !getScaleDetector().isInProgress() ) {
        if ( isDetectMovementX() ) {
            final float dx = x - getLastTouchX();
            setPosX( getPosX() + dx );
        }

        if ( isDetectMovementY() ) {
            final float dy = y - getLastTouchY();
            setPosY( getPosY() + dy );
        }

        invalidate();
    }

    setLastTouchX( x );
    setLastTouchY( y );

    if ( isAtXBound() ) {
        return false;
    }

    break;
}

查看缩放和平移,但图库从不滚动。我不知道是否有一种方法基本上重新发送 MotionEvent 作为新鲜 MotionEvent 与最初的行动是 ACTION_DOWN 。谢谢!

The View zooms and translates, but the Gallery never scrolls. I'm wondering if there's a way to basically resend the MotionEvent as a "fresh" MotionEvent with the initial action being ACTION_DOWN. Thanks!

推荐答案

您可以使用 MotionEvent 的构造函数创建一个新的。请参阅文章

You can use MotionEvent's constructor to create a new one. See the article Android: How to create a MotionEvent?

此外,获得(...)方法创建一个新的 MotionEvent 。尝试 MotionEvent E = MotionEvent.obtain(事件);

Also, the obtain(...) method creates a new MotionEvent. Try MotionEvent e = MotionEvent.obtain(event);

请参阅更多关于>获得。

See this link for more about obtain.

这篇关于我如何与QUOT;重启"在Android的触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!