【问题标题】:Android CircularReveal library View visibility bugAndroid CircularReveal 库查看可见性错误
【发布时间】:2016-03-12 23:30:27
【问题描述】:

我使用 this 库在棒棒糖之前的设备上创建 CircularReveal 动画。问题在于用动画隐藏View。动画也会执行,但在动画结束后,View 会出现一秒钟然后消失。如何防止View 闪烁?

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

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()");

                }
            });

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

【问题讨论】:

    标签: android animation view invisible circularreveal


    【解决方案1】:

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

    android:animateLayoutChanges="true"
    

    根视图组中的属性。

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 我试着这样做。问题是 onAnimationEnd() 从未被调用,我不知道为什么。所以,我决定使用postDelayed(),现在我闪烁View
      猜你喜欢
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-20
      • 2015-04-20
      • 1970-01-01
      相关资源
      最近更新 更多