首页 > 移动平台 > 详细

Android属性动画-简单实例

时间:2019-05-15 15:18:07      阅读:151      评论:0      收藏:0      [点我收藏+]

1.ValueAnimator

//在2000毫秒内,将值从0过渡到1的动画
        ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
        anim.setDuration(2000);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float currentValue = (float) valueAnimator.getAnimatedValue();
                Log.e("tag", "currentValue="+currentValue);
                String textStr = ((int) (currentValue * 60)) + "";
                text1_tv.setText(textStr);
            }
        });
        anim.start();

技术分享图片

2.ObjectAnimator

//将TextView从常规变换成全透明,再从全透明变换成常规
        ObjectAnimator anim1 = ObjectAnimator.ofFloat(text2_tv, "alpha", 1f, 0f, 1f);
        anim1.setDuration(3000);
        anim1.start();
        //将TextView进行一次360度的旋转
        ObjectAnimator anim2 = ObjectAnimator.ofFloat(text2_tv, "rotation", 0f, 360f);
        anim2.setDuration(3000);
        anim2.start();
        //将TextView先向左移出屏幕,然后再移动回来
        float curTranslationX = text2_tv.getTranslationX();
        ObjectAnimator anim3 = ObjectAnimator.ofFloat(text2_tv, "translationX", curTranslationX, -500f, curTranslationX);
        anim3.setDuration(3000);
        anim3.start();
        //将TextView在垂直方向上放大3倍再还原
        ObjectAnimator anim4 = ObjectAnimator.ofFloat(text2_tv, "scaleY", 1f, 3f, 1f);
        anim4.setDuration(5000);
        anim4.start();

技术分享图片

3.组合动画

//让TextView先从屏幕外移动进屏幕,然后开始旋转360度,旋转的同时进行淡入淡出操作
        ObjectAnimator moveIn = ObjectAnimator.ofFloat(text3_tv, "translationX", -500f, 0f);
        ObjectAnimator rotate = ObjectAnimator.ofFloat(text3_tv, "rotation", 0f, 360f);
        ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(text3_tv, "alpha", 1f, 0f, 1f);
        AnimatorSet animSet = new AnimatorSet();
        animSet.play(rotate).with(fadeInOut).after(moveIn);
        animSet.setDuration(5000);
        animSet.start();

 技术分享图片

Android属性动画-简单实例

原文:https://www.cnblogs.com/chenzheng8975/p/10869333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!