安卓(Android) 怎么创建 Pan Out动画(Animation)

2019年10月15日20:12:56安卓(Android) 怎么创建 Pan Out动画(Animation)已关闭评论 247 903字阅读3分0秒

1.简介

安卓(Android) 怎么创建 Pan Out动画(Animation)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;

import android.view.animation.ScaleAnimation;

public class Main {
    private static final long MEDIUM = 500;

    public static Animation createPanOutAnim(float degree) {
        AnimationSet ret;
        Animation anim;
        ret = new AnimationSet(false);

        anim = new AlphaAnimation(1f, 0f);
        anim.setDuration(MEDIUM);
        anim.setInterpolator(new DecelerateInterpolator());
        ret.addAnimation(anim);

        final float pivotX = (float) (1 + Math.cos(degree)) / 2;
        final float pivotY = (float) (1 - Math.sin(degree)) / 2;
        anim = new ScaleAnimation(1, 0.8f, 1, 0.8f,
                Animation.RELATIVE_TO_SELF, pivotX,
                Animation.RELATIVE_TO_SELF, pivotY);
        anim.setDuration(MEDIUM);
        anim.setInterpolator(new DecelerateInterpolator());
        ret.addAnimation(anim);

        return ret;
    }
}

 
继续阅读
编程十万个怎么办