关于super.onBackPressed()动画显示

时间:2018-05-11 13:23:14

标签: android android-animation uiviewanimationtransition

Android关于super.onBackPressed()animate揭示

  • 在android登录程序中,单击右下方的注册按钮以显示注册页面的打开动画,然后左下方会出现一个动画,返回到登录页面按钮.OK,所有这一切很好。

  • 我会点击页面底部的左侧登录按钮,会有动画关闭注册页面,底部右侧显示的动画会显示登录页面按钮但是实现有问题。关闭动画后,显示登录页面的按钮动画无法显示。我想因为RegisterActivity. Super. OnBackPressed ()我不知道该怎么做。谢谢

  

源代码:

 /**
 * Close the page animation
 */
public void animateRevealClose() {
    int centerX = (mCardViewRegister.getWidth()) / 2;
    int centerY = (mToSignUpCardView.getTop() + mToSignUpCardView.getBottom()) / 2;
    int startRadius = mCardViewRegister.getHeight();
    int endRadius = mToSignUpCardView.getWidth() / 2;
    Animator mAnimator = ViewAnimationUtils.createCircularReveal(
            mCardViewRegister,
            centerX,
            centerY,
            startRadius,
            endRadius);
    mAnimator.setDuration(500);
    mAnimator.setInterpolator(new AccelerateInterpolator());
    mAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            BottomFastSignUp(); //The bottom button displays the animation.
            mCardViewRegister.setVisibility(View.INVISIBLE);
            super.onAnimationEnd(animation);
            RegisterActivity.super.onBackPressed();
        }

        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
        }
    });
    mAnimator.start();}

方法onBackPressed()

  @Override
public void onBackPressed() {
    animateRevealClose();
    super.onBackPressed();
}

1 个答案:

答案 0 :(得分:0)

这是我从讨论中理解的:

<强> 1 /

按下后退按钮时启动关闭动画,但随后立即调用super.onBackPressed()使活动结束,任何动画设置都无效。

所以删除super.onBackPressed();是第一个修复。

<强> 2 /

在近距离动画的结束事件中,您调用BottomFastSignUp这是另一个动画,但再次调用RegisterActivity.super.onBackPressed();。这使活动完成,动画再次无用。

所以要解决这个问题,在所有动画完成之前不要完成活动。

有两个选项需要修复:

  • 收听BottomFastSignUp动画结束并在那里拨打finish
  • BottomFastSignUp移至LoginActivity。您可以完成RegisterActivity,覆盖onActivityReenter中的LoginActivity,然后执行BottomFastSignUp