Performing action after fragment transaction animation is finished

前端 未结 5 593
旧巷少年郎
旧巷少年郎 2020-11-30 01:23

I want to set a buttons visibility after the animation is finished.

That\'s what calls the animation:

android.support.v4.app.FragmentTransaction fAni         


        
5条回答
  •  醉梦人生
    2020-11-30 01:46

    The Animators that @nmw implements in his answer were added in API Level 11 and will not work with Fragments as implemented by the Android support library.

    To listen to Fragment animation events, I extended the support library's Fragment class and overrode onCreateAnimation, attaching a custom AnimationListener to the returned Animation object:

    public class MyFragment extends android.support.v4.app.Fragment {
    
        private static final String TAG = "MyFragment";
    
        @Override
        public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    
            Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim);
    
            anim.setAnimationListener(new AnimationListener() {
    
                @Override
                public void onAnimationStart(Animation animation) {
                    Log.d(TAG, "Animation started.");
                    // additional functionality 
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
                    Log.d(TAG, "Animation repeating.");
                    // additional functionality
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
                    Log.d(TAG, "Animation ended.");
                    // additional functionality
                }
            });
    
            return anim;
        }
    }
    

提交回复
热议问题