动画时禁用所有触摸屏交互

2024-02-01

我希望在显示动画时禁用所有触摸屏交互。 我不想使用setClickable()方法在动画开始或结束时的按钮上,因为有大量按钮。有什么建议么?


在您的 Activity 中,您可以覆盖onTouchEvent而且总是return true;指示您正在处理触摸事件。

您可以找到该功能的文档there http://developer.android.com/reference/android/app/Activity.html#onTouchEvent%28android.view.MotionEvent%29.

Edit这是一种可以禁用整个屏幕触摸的方法,而不是逐个处理每个视图...首先更改当前的布局,如下所示:

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    < .... put your current layout here ... />

    <TouchBlackHoleView
        android:id="@+id/black_hole"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</FrameLayout>

然后使用如下内容定义您的自定义视图:

public class TouchBlackHoleView extends View {
    private boolean touch_disabled=true;
    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return touch_disabled;
    }
    public disable_touch(boolean b) {
        touch_disabled=b;
    }
}

然后,在活动中,您可以禁用触摸

(TouchBlackHoleView) black_hole = findViewById(R.id.black_hole);
black_hole.disable_touch(true);

并启用它

black_hole.disable_touch(false);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

动画时禁用所有触摸屏交互 的相关文章

随机推荐