在我的应用程序中禁用多指触摸 [英] Disable multi finger touch in my app

查看:44
本文介绍了在我的应用程序中禁用多指触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用一个 Activity 来托管多个片段.手机屏幕上每次显示一个片段.每个片段的视图由多个图像图标组成.

My app uses one Activity to host several fragments. Each time one fragment is shown on the phone screen.The view of each fragment consists of several image icons.

目前,用户可以用两个手指同时按下两个图标(每个手指按下一个图标).我想在我的应用中禁用此多点触控功能,以便一次只按下一个图标.

Currently, user is able to press on two icons simultaneously with two fingers (with each fingure press on one icon). I want to disable this multi-touch feature on my app to allow only one icon press take effect at a time.

我尝试了以下方法:

方式 1:在我的应用主题中,我添加了:

Way 1: in my app theme, I added:

<item name="android:windowEnableSplitTouch">false</item>

方式 2: 在 Android Manifest xml 中,我添加了:

Way 2: In Android Manifest xml, I added:

<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />

方式 3:在我的活动中:

@Override
public boolean onTouchEvent(MotionEvent event) {

    if(event.getPointerCount() > 1) {
        System.out.println("Multitouch detected!");
        return true;
    }
    else
       return super.onTouchEvent(event);
    }

不幸的是,我的解决方案均无效.那么,如何在我的应用中禁用多点触控功能?

Unfortunately, none of my solutions work. So, How can I disable multi-touch feature in my app??

推荐答案

例如:您有多个按钮,而您希望只选择一个按钮.在按钮的父级(不是ROOT,只是子级的父级)中,在其xml 参数中添加

For case: you have multiple buttons and you want make selected only one button. In parent (NOT ROOT, just parent of child) of buttons, in its xml params add

android:splitMotionEvents="false"

android:splitMotionEvents="false"

就是这样.示例:

<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).我希望你能明白.:)

Btw. When you have 2 linearlayout with 3 buttons per layout, you should set this splitMotionEvents in that two layouts and also in parent of that 2 linearLayouts. Otherwise you will be able click only one button per layout (sum = 2 then). I hope you get it. :)

其他解决方案都没有对我有用或太蹩脚.

None of the other solutions didn't work for me or was too lame.

这篇关于在我的应用程序中禁用多指触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆