![](/img/trans.png)
[英]Android ListView onTouchEvent doesn't always give 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
事件。 这意味着您处理了该事件,因此您可以接收下一个事件。
在工作中,我们有一个名为teaser
的LinearLayout
,它有类似的问题(已经有一段时间了)。 无论如何,我们发现这种“黑客”似乎有助于从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.