我的应用程序使用一个 Activity 来托管多个片段。每次在手机屏幕上显示一个片段。每个片段的视图由多个图像图标组成。
目前,用户可以按两个图标同时地用两根手指(每根手指按一个图标)。我想禁用此多点触控功能在我的应用程序上允许一次只能按下一个图标生效.
我尝试了以下方法:
Way 1:在我的应用程序主题中,我添加了:
<item name="android:windowEnableSplitTouch">false</item>
Way 2:在 Android Manifest xml 中,我添加了:
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
Way 3:在我的活动中:
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getPointerCount() > 1) {
System.out.println("Multitouch detected!");
return true;
}
else
return super.onTouchEvent(event);
}
不幸的是,我的解决方案都不起作用。所以,如何禁用多点触控功能在我的应用程序中?
例如:您有多个按钮,而您只想选择一个按钮。在父母中(不是根,只是子级的父级)按钮,在其 xml 参数中添加
安卓:splitMotionEvents =“假”
就是这样。
例子:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:splitMotionEvents="false" <-----------!!!
>
<Button
android:id="@+id/button_main_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1" />
<Button
android:id="@+id/button_main_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
<Button
android:id="@+id/button_main_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3" />
</LinearLayout>
顺便提一句。当你有 2 个线性布局,每个布局有 3 个按钮时,你应该在这两个布局中设置 splitMotionEvents也在父母身上这 2 个线性布局。否则,您将只能在每个布局中单击一个按钮(此时总和 = 2)。我希望你能明白。 :)
其他解决方案都对我不起作用或太蹩脚。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)