我想禁用所有的触摸屏交互显示动画的同时。
我不希望上的按钮使用 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.
您可以找到该功能的文档有的。
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);