AnimationUtils.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:Xndroid 作者:
/**
 * Creates an animation that rotates an {@link ImageView}
 * around the Y axis by 180 degrees and changes the image
 * resource shown when the view is rotated 90 degrees to the user.
 *
 * @param imageView   the view to rotate.
 * @param drawableRes the drawable to set when the view
 *                    is rotated by 90 degrees.
 * @return an animation that will change the image shown by the view.
 */
@NonNull
public static Animation createRotationTransitionAnimation(@NonNull final ImageView imageView,
                                                          @DrawableRes final int drawableRes) {
    Animation animation = new Animation() {

        private boolean mSetFinalDrawable;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime < 0.5f) {
                imageView.setRotationY(90 * interpolatedTime * 2f);
            } else {
                if (!mSetFinalDrawable) {
                    mSetFinalDrawable = true;
                    imageView.setImageResource(drawableRes);
                }
                imageView.setRotationY((-90) + (90 * (interpolatedTime - 0.5f) * 2f));
            }
        }
    };

    animation.setDuration(300);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());

    return animation;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号