繁体   English   中英

为什么我总是从onTouchEvent获得ACTION_DOWN

[英]why I always get ACTION_DOWN from onTouchEvent

我从View扩展我的课程。 并重写onTouchEvent函数。 但是,我只能获得ACTION_DOWN事件。 不是任何ACTION_UP或ACTION_MOVE。 我应该怎么做才能得到那些事件?

我只覆盖onTouchEvent和onDraw函数。 应用程序中只有这个视图

@Override
public boolean onTouchEvent(MotionEvent event) {
    System.out.println("event:"+event.getAction());
    return super.onTouchEvent(event);
}

可能你需要返回true而不是返回super事件。 这意味着您处理了该事件,因此您可以接收下一个事件。

在工作中,我们有一个名为teaserLinearLayout ,它有类似的问题(已经有一段时间了)。 无论如何,我们发现这种“黑客”似乎有助于从touch获得一些额外的响应。

teaser.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent motionEvent) {
        TransitionDrawable transition = (TransitionDrawable) v.getBackground();

        switch(motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if(transition != null) transition.startTransition(250);
                break;
            case MotionEvent.ACTION_UP:
                loadArticle(position);
            case MotionEvent.ACTION_CANCEL:
                if(transition != null) transition.reverseTransition(0);
                break;
        }
        return false;
    }
});

// Has to be here for the touch to work properly.
teaser.setOnClickListener(null); // <-- the important part for you

老实说,我不能给你任何押韵或理由,但希望这有帮助。

这篇文章可以帮助您了解发生了什么: http//rxwen.blogspot.com/2010/07/implement-drag-and-drop-on-android.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM