Disable All Touch Screen Interactions While Animation
Solution 1:
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:
<FrameLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"
>
< .... put your current layout here ... />
<TouchBlackHoleViewandroid: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:
publicclassTouchBlackHoleViewextendsView {
privateboolean touch_disabled=true;
@OverridepublicbooleanonTouchEvent(MotionEvent e) {
return touch_disabled;
}
publicdisable_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);
And enable it back with
black_hole.disable_touch(false);
Solution 2:
Easy way to implement that is add transaperent layout over it (add it in your xml fill parent height and width).
In the animation start: transaparentlayout.setClickable(true);
In the animation end: transaparentlayout.setClickable(false);
Solution 3:
answer to this issue
for (int i = 1; i < layout.getChildCount(); i++) {
TableRow row = (TableRow) layout.getChildAt(i);
row.setClickable(false);
selected all the rows of the table layout which had all the views and disabled them
Solution 4:
Eventually I took as a basic answer of @Matthieu and make it work such way. I decide to publish my answer because it take me maybe 30 min to understood why I got error.
XML
<...your path to this view andin the end--> .TouchBlackHoleView
android:id="@+id/blackHole"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Class
public class TouchBlackHoleView extends View { private boolean touchDisable = false;
publicTouchBlackHoleView(Context context) {
super(context);
}
publicTouchBlackHoleView(Context context, AttributeSet attrs) {
super(context, attrs);
}
publicTouchBlackHoleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@OverridepublicbooleanonTouchEvent(MotionEvent event) {
return touchDisable;
}
publicvoiddisableTouch(boolean value){
touchDisable = value;
}
}
Using
blackHole = (TouchBlackHoleView) findViewById(R.id.blackHole);
blackHole.disableTouch(true);
Enjoy
Post a Comment for "Disable All Touch Screen Interactions While Animation"