在setCustomAnimationcallback之前和之后的FragmentTransaction

我正在使用自定义animationreplace片段,我想在animation开始时禁用一些button,然后在animation结束时启用。 我怎样才能做到这一点?

Solutions Collecting From Web of "在setCustomAnimationcallback之前和之后的FragmentTransaction"

我会build议做一些基础类,所有的Fragments扩展,并在其中,定义一些可以重写处理animation事件的方法。 然后,重写onCreateAnimation() (假设你正在使用支持库)来发送animationcallback事件。 例如:

 protected void onAnimationStarted () {} protected void onAnimationEnded () {} protected void onAnimationRepeated () {} @Override public Animation onCreateAnimation (int transit, boolean enter, int nextAnim) { //Check if the superclass already created the animation Animation anim = super.onCreateAnimation(transit, enter, nextAnim); //If not, and an animation is defined, load it now if (anim == null && nextAnim != 0) { anim = AnimationUtils.loadAnimation(getActivity(), nextAnim); } //If there is an animation for this fragment, add a listener. if (anim != null) { anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart (Animation animation) { onAnimationStarted(); } @Override public void onAnimationEnd (Animation animation) { onAnimationEnded(); } @Override public void onAnimationRepeat (Animation animation) { onAnimationRepeated(); } }); } return anim; } 

然后,对于Fragment子类,只需重写onAnimationStarted()以禁用button,然后使用onAnimationEnded()启用button。