2

我使用这个库在棒棒糖之前的设备上创建 CircularReveal 动画。问题在于View动画隐藏。动画也会执行,但在动画结束后,View会显示一秒钟然后消失。我怎样才能防止眨眼View

这是我View用 CircularReveal 动画隐藏的方法:

public static void revealCloseTopRight(final View view) {
            int cx = view.getRight();
            int cy = view.getTop();

            // get the final radius for the clipping circle
            int dx = Math.max(cx, view.getWidth() - cx);
            int dy = Math.max(cy, view.getHeight() - cy);
            float finalRadius = (float) Math.hypot(dx, dy);

            SupportAnimator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(animDuration);
            animator = animator.reverse();

            try {
                animator.start();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    view.setVisibility(View.INVISIBLE);
                }
            }, animDuration);
        }

更新

我也尝试这样添加SupportAnimator.AnimatorListener()

animator.addListener(new SupportAnimator.AnimatorListener() {
                @Override
                public void onAnimationStart() {
                    Log.d(AnimationSupport.TAG, TAG + " -> 1onAnimationStart()");

                }

                @Override
                public void onAnimationEnd() {
                    Log.d(AnimationSupport.TAG, TAG + " -> 1onAnimationEnd()");
                    view.setVisibility(View.INVISIBLE);
                }

                @Override
                public void onAnimationCancel() {
                    Log.d(AnimationSupport.TAG, TAG + " -> 1onAnimationCancel()");

                }

                @Override
                public void onAnimationRepeat() {
                    Log.d(AnimationSupport.TAG, TAG + " -> 1onAnimationRepeat()");

                }
            });

像这样Animator.AnimatorListener()

animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    Log.d(AnimationSupport.TAG, TAG + " -> onAnimationStart()");

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    Log.d(AnimationSupport.TAG, TAG + " -> onAnimationEnd()");
                    view.setVisibility(View.INVISIBLE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    Log.d(AnimationSupport.TAG, TAG + " -> onAnimationCancel()");

                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                    Log.d(AnimationSupport.TAG, TAG + " -> onAnimationRepeat()");

                }
            });

在这两种情况下,都不会调用此回调。我不知道为什么。

4

2 回答 2

1

确保在您尝试为视图设置动画的布局中,没有

android:animateLayoutChanges="true"

根视图组中的属性。

删除它将帮助您克服动画结束后的闪烁视图并将可见性设置为 GONE(或 INVISIBLE)。

于 2019-09-26T15:45:45.723 回答
0

视图是可见的,因为动画完成和处理程序执行之间存在非常小的延迟。

您可以通过向循环显示动画添加动画侦听器并在onAnimationEnd()回调中将视图设置为不可见来解决此问题。

于 2016-03-13T00:15:13.107 回答