为什么 getAction 方法总是返回 ACTION_DOWN? [英] Why getAction method always return ACTION_DOWN?
问题描述
我使用 onTouchListener 进行布局.我想在布局之外点击.我为布局设置了 onTouchListener .但运动事件总是显示 ACTION_DOWN.即使我 touchOutside 视图,它也没有显示 ACTION_OUTSIDE.谁能帮我找出为什么它没有显示恒定的 ACTION_OUTSIDE.这是我正在使用的代码
I am using onTouchListener for a layout. I want to take the click outside the layout. I set onTouchListetener for the layout. But motion event always shows ACTION_DOWN. Even i touchOutside the view, It is not showing ACTION_OUTSIDE. Could anyone help me to find out why it is not showing constant ACTION_OUTSIDE. Here is the code i am using
Layout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("action",event.getAction()+"");
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
Toast.makeText(getApplicationContext(), "check", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
推荐答案
如果您返回 false
,则表示您不希望接收更多触摸事件.您需要返回 true
才能继续获取运动事件.
If you return false
, then you're signifying that you do not wish to receive further touch events. You need to return true
to continue getting motion events.
这篇关于为什么 getAction 方法总是返回 ACTION_DOWN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!