android – 自定义循环显示转换结果在“java.lang.UnsupportedOperationException”暂停时?

前端之家收集整理的这篇文章主要介绍了android – 自定义循环显示转换结果在“java.lang.UnsupportedOperationException”暂停时?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个自定义循环显示转换,以作为Activity的输入转换的一部分(具体来说,我通过调用Window#setEnterTransition())来设置转换为窗口的转换.
public class CircularRevealTransition extends Visibility {
    private final Rect mStartBounds = new Rect();

    /**
     * Use the view's location as the circular reveal's starting position.
     */
    public CircularRevealTransition(View v) {
        int[] loc = new int[2];
        v.getLocationInWindow(loc);
        mStartBounds.set(loc[0],loc[1],loc[0] + v.getWidth(),loc[1] + v.getHeight());
    }

    @Override
    public Animator onAppear(ViewGroup sceneRoot,final View v,TransitionValues startValues,TransitionValues endValues) {
        if (endValues == null) {
            return null;
        }
        int halfWidth = v.getWidth() / 2;
        int halfHeight = v.getHeight() / 2;
        float startX = mStartBounds.left + mStartBounds.width() / 2 - halfWidth;
        float startY = mStartBounds.top + mStartBounds.height() / 2 - halfHeight;
        float endX = v.getTranslationX();
        float endY = v.getTranslationY();
        v.setTranslationX(startX);
        v.setTranslationY(startY);

        // Create a circular reveal animator to play behind a shared
        // element during the Activity Transition.
        Animator revealAnimator = ViewAnimationUtils.createCircularReveal(v,halfWidth,halfHeight,0f,FloatMath.sqrt(halfWidth * halfHeight + halfHeight * halfHeight));
        revealAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Set the view's visibility to VISIBLE to prevent the
                // reveal from "blinking" at the end of the animation.
                v.setVisibility(View.VISIBLE);
            }
        });

        // Translate the circular reveal into place as it animates.
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("translationX",startX,endX);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("translationY",startY,endY);
        Animator translationAnimator = ObjectAnimator.ofPropertyValuesHolder(v,pvhX,pvhY);

        AnimatorSet anim = new AnimatorSet();
        anim.setInterpolator(getInterpolator());
        anim.playTogether(revealAnimator,translationAnimator);
        return anim;
    }
}

这样可以正常工作.但是,当我在转换过程中单击“返回按钮”时,我得到以下异常:

Process: com.adp.activity.transitions,PID: 13800
java.lang.UnsupportedOperationException
        at android.view.RenderNodeAnimator.pause(RenderNodeAnimator.java:251)
        at android.animation.AnimatorSet.pause(AnimatorSet.java:472)
        at android.transition.Transition.pause(Transition.java:1671)
        at android.transition.TransitionSet.pause(TransitionSet.java:483)
        at android.app.ActivityTransitionState.startExitBackTransition(ActivityTransitionState.java:269)
        at android.app.Activity.finishAfterTransition(Activity.java:4672)
        at com.adp.activity.transitions.DetailsActivity.finishAfterTransition(DetailsActivity.java:167)
        at android.app.Activity.onBackPressed(Activity.java:2480)

有什么具体原因我收到这个错误吗?应该如何避免?

解决方法

您将需要创建Animator的子类,忽略对pause()和resume()的调用,以避免此异常.

有关更多详细信息,我刚刚完成了有关此主题文章

>第1部分:http://halfthought.wordpress.com/2014/11/07/reveal-transition/
>第2部分:https://halfthought.wordpress.com/2014/12/02/reveal-activity-transitions/

原文链接:https://www.f2er.com/android/312835.html

猜你在找的Android相关文章