在OnTouch返回false上的ImageView,但仍事件得到消耗 [英] Returning false in OnTouch on ImageView but still event is getting consumed
本文介绍了在OnTouch返回false上的ImageView,但仍事件得到消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 ImageView.onTouch()
。
我为 ACTION_MOVE
,但仍是 onTouch()
事件被消耗。
I am using ImageView.onTouch()
.
I am returning false for ACTION_MOVE
but still the onTouch()
event is consumed.
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent ev) {
System.out.println("jan25 iv onTouch");
if (ev.getActionMasked()==MotionEvent.ACTION_DOWN) {
System.out.println("jan25 iv ACTION_DOWN");
return true;
}
if (ev.getActionMasked()==MotionEvent.ACTION_MOVE){
System.out.println("jan25 iv ACTION_MOVE");
return false;
}
if (ev.getActionMasked()==MotionEvent.ACTION_UP){
System.out.println("jan25 iv ACTION_UP");
return true;
}
System.out.println("jan25 iv false");
return false;
}
});
布局:
<LinearLayout
android:id="@+id/ll_magic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/red"
android:orientation="vertical" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abcd"
/>
</LinearLayout>
任何想法请
推荐答案
这工作过,但我仍然不是100%肯定你是问做什么。这台ImageView的点击为false,因此应允许触摸不要被它消耗掉。另外,我增加点击到的LinearLayout。
This works too, but I'm still not 100% sure what you are asking to do. This sets the imageView clickable to false and should therefore allow the touch not to be consumed by it. Also, I added clickable to the LinearLayout.
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent ev) {
System.out.println("jan25 iv onTouch");
if (ev.getActionMasked()==MotionEvent.ACTION_DOWN) {
System.out.println("jan25 iv ACTION_DOWN");
return true;
}
if (ev.getActionMasked()==MotionEvent.ACTION_MOVE){
System.out.println("jan25 iv ACTION_MOVE");
imageView.setClickable(false);
return false;
}
if (ev.getActionMasked()==MotionEvent.ACTION_UP){
System.out.println("jan25 iv ACTION_UP");
return true;
}
System.out.println("jan25 iv false");
return false;
}
});
<LinearLayout
android:id="@+id/ll_magic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/red"
android:clickable = "true"
android:orientation="vertical" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abcd"
/>
</LinearLayout>
这篇关于在OnTouch返回false上的ImageView,但仍事件得到消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文