I have a method, which perform a fragment adding animation and a new fragment fills all screen:
public void addFragmentWithAnimation(Fragment fragment, boolean addToBackStack){
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_right);
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.add(R.id.lay_fragments, fragment);
commitTransaction(transaction);
}
But when animation playing user still allowed to click on buttons on the view below and make another ui actions, which could cause to unpredictable results. Is there an any way to block all user actions in app, until the end of animation?
A modification of Beloo's answer for non-support Fragments keeps the code encapsulated a bit better. Just use the start and stop of the listener to set and clear the flag...
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
@Override
public void onAnimationEnd(Animator animator) {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
});
}
return animator;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With