我希望在显示动画禁用所有触摸屏交互。 我不希望使用setClickable()
在开始或动画的结束,因为有大量的按钮的方法上的按钮。 有什么建议?
Answer 1:
在您的活动,您可以覆盖onTouchEvent
始终return true;
以表示你要处理的触摸事件。
您可以找到该函数的文档存在 。
编辑这里是你可以禁用在整个屏幕触摸,而不是由一个处理每一个观点...首先改变你目前的布局是这样一种方式:
<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);
Answer 2:
回答这个问题
for (int i = 1; i < layout.getChildCount(); i++) { TableRow row = (TableRow) layout.getChildAt(i); row.setClickable(false);
选择所有的表格布局的行构成了各方面的意见,并禁止他们
Answer 3:
最后,我把作为@Matthieu的一个基本答案,并使其发挥作用这样的方式。 我决定公开我的答案,因为它把我也许30分钟,明白了为什么我的错误。
XML
<...your path to this view and in the end --> .TouchBlackHoleView
android:id="@+id/blackHole"
android:layout_width="match_parent"
android:layout_height="match_parent" />
类
公共类TouchBlackHoleView扩展视图{私人布尔touchDisable = FALSE;
public TouchBlackHoleView(Context context) {
super(context);
}
public TouchBlackHoleView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TouchBlackHoleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return touchDisable;
}
public void disableTouch(boolean value){
touchDisable = value;
}
}
运用
blackHole = (TouchBlackHoleView) findViewById(R.id.blackHole);
blackHole.disableTouch(true);
请享用
Answer 4:
实现一个简单的方法是在它添加transaperent布局(在你的XML填充家长的高度和宽度添加它)。
在动画开始: transaparentlayout.setClickable(true);
在动画结束: transaparentlayout.setClickable(false);
文章来源: Disable All Touch Screen Interactions While Animation