onTouchListener不工作 [英] onTouchListener not working
问题描述
我有以下的code。在我的活动。在我的XML,视频的看法是线性布局中。然而,该视图被点击时,在 onTouchListener
永远不会触发。我试图改变 onTouchListener
到 vvLive
但这并没有做任何事情。我也试图改变 onTouchListener
到 onClickListener
,但没有。任何人都知道为什么监听器在不触发?谢谢你。
I have the following code in my activity. In my xml, the video view is inside the linear layout. However, when the view is clicked, the onTouchListener
never fires. I tried changing the onTouchListener
to vvLive
but that didn't do anything. I also tried changing the onTouchListener
to an onClickListener
, but nothing. Anyone know why the listener isn't firing? Thanks.
private VideoView vvLive;
LinearLayout linearLayoutLiveVideo;
linearLayoutLiveVideo.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
Log.d(TAG, "onTouch entered");
if(event.getAction() == MotionEvent.ACTION_UP) {
Log.d(TAG, "ACTION_UP");
}
return false;
}
});
修改:
我实现了code以上的实际工作。东西在月食被搞乱LogCat中。当我重新启动日食,LogCat中打印的第一个日志onTouch进入。然而,ACTION_UP没有被打印。我改变了MotionEvent为 MotionEvent.ACTION_DOWN
现在LogCat中打印。为什么 ACTION_DOWN
的工作,但 ACTION_UP
不?
EDIT:
I realized the code above actually works. Something in eclipse was messing up LogCat. After I restarted eclipse, LogCat prints the first log "onTouch entered". However, "ACTION_UP" was not being printed. I changed the MotionEvent to MotionEvent.ACTION_DOWN
and the LogCat prints now. Why does ACTION_DOWN
work but ACTION_UP
does not?
推荐答案
ACTION_UP永远不会被发送到你的听众,因为你返回false,并为此不消费的事件。返回true,你会得到的启动事件(ACTION_DOWN)以及所有后续的(ACTION_MOVE然后ACTION_UP)。
ACTION_UP is never being sent to your listener because you return false and therefor don't "consume" the event. Return true and you'll get the start event (ACTION_DOWN) as well as all the subsequent ones (ACTION_MOVE and then ACTION_UP).
这篇关于onTouchListener不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!