关闭

android学习笔记 视图动画

标签: android动画Animation
50人阅读 评论(0) 收藏 举报
分类:
/**
 * 视图动画
 */
public class ViewAnim extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_anim);
    }

    /**
     * 透明度动画
     *
     * @param view
     */
    public void btnAlpha(View view) {

        AlphaAnimation aa = new AlphaAnimation(0, 1);
        aa.setDuration(1000);
        view.startAnimation(aa);

    }

    /**
     * 旋转动画
     *
     * @param view
     */
    public void btnRotate(View view) {

        RotateAnimation ra = new RotateAnimation(0, 360, 100, 100);
        ra.setDuration(1000);
        view.startAnimation(ra);

    }

    /**
     * 旋转动画设置参考系(自身中心点)
     * @param view
     */
    public void btnRotateSelf(View view) {

        RotateAnimation ra = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5F, RotateAnimation.RELATIVE_TO_SELF, 0.5F);
        ra.setDuration(1000);
        view.startAnimation(ra);

    }

    /**
     * 位移动画
     * @param view
     */
    public void btnTranslate(View view){

        TranslateAnimation ta = new TranslateAnimation(0,200,0,300);
        ta.setDuration(1000);
        view.startAnimation(ta);

    }

    /**
     * 缩放动画
     * @param view
     */
    public void btnScale(View view){

        ScaleAnimation sa = new ScaleAnimation(0,2,0,2);
        sa.setDuration(1000);
        view.startAnimation(sa);

    }

    /**
     * 缩放动画设置参考系(自身中心点)
     * @param view
     */
    public void btnScaleSelf(View view){

        ScaleAnimation sa = new ScaleAnimation(0, 1,0,1, RotateAnimation.RELATIVE_TO_SELF, 0.5F, RotateAnimation.RELATIVE_TO_SELF, 0.5F);
        sa.setDuration(1000);
        view.startAnimation(sa);

    }

    /**
     * 动画集合
     * @param view
     */
    public void btnSet(View view){

        AnimationSet as = new AnimationSet(true);
        as.setDuration(1000);

        AlphaAnimation aa = new AlphaAnimation(0, 1);
        aa.setDuration(1000);
        as.addAnimation(aa);

        TranslateAnimation ta = new TranslateAnimation(0,200,0,300);
        ta.setDuration(1000);
        as.addAnimation(ta);
        
        view.startAnimation(as);

    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3378次
    • 积分:225
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    最新评论