禁用所有触摸屏交互虽然动画 [英] Disable All Touch Screen Interactions While Animation

查看:129
本文介绍了禁用所有触摸屏交互虽然动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wish to disable all the touch screen interactions while an animation is being displayed. I don't wish to use the setClickable() method on the buttons at the start or end of the animation because there are a large number of buttons. Any suggestions?

推荐答案

在你的活动,你可以覆盖的onTouchEvent 总是返回true; 来表示你正在处理的触摸事件。

In your Activity, you can override onTouchEvent and always return true; to indicate you are handling the touch events.

您可以找到该功能的文档<一href="http://developer.android.com/reference/android/app/Activity.html#onTouchEvent%28android.view.MotionEvent%29"相对=nofollow>有的。

You can find the documentation for that function there.

修改这里是你可以禁用触摸在整个屏幕,而不是处理每个视图一个接一个......首先改变你当前的布局像这样的方式:

Edit Here is one way you can disable touch over the whole screen instead of handling every view one by one... First change your current layout like this:

<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>

再有像这样定义您的自定义视图:

And then define your custom view with something like this:

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;
    }
}

那么,在活动中,您可以禁用与触摸

Then, in the activity, you can disable the touch with

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

和启用它回来了

black_hole.disable_touch(false);

这篇关于禁用所有触摸屏交互虽然动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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