android 简单快速 倒计时动画

需求:执行5次动画效果,也就是 5秒倒计时 

        int repeatCount=4;//定义重复字数(执行动画1次 + 重复动画4次 = 公共5次)

        // 设置透明度渐变动画
        final AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(910);//动画持续时间(定义900~1000,也就是1秒左右)
        alphaAnimation.setRepeatMode(Animation.RESTART);
        alphaAnimation.setRepeatCount(repeatCount);
        alphaAnimation.setInterpolator(new LinearInterpolator());
        // 设置缩放渐变动画
        final ScaleAnimation scaleAnimation =new ScaleAnimation(0.5f, 1f, 0.5f,1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(910);//动画持续时间(定义900~1000,也就是1秒左右)
        scaleAnimation.setRepeatMode(Animation.RESTART);
        scaleAnimation.setRepeatCount(repeatCount);
        scaleAnimation.setInterpolator(new LinearInterpolator());

        AnimationSet animationSet=new AnimationSet(false);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(scaleAnimation);


        tvCountDown.startAnimation(animationSet);
        //这里 alphAnimation 设置监听,不能用 animationSet 做监听
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            int count=repeatCount+1;// 加1为第一次要显示的数字 5
            @Override
            public void onAnimationStart(Animation animation) {// 此方法执行1次
                tvCountDown.setVisibility(View.VISIBLE);
                tvCountDown.setText(""+count);//设置显示的数字
                count--;
            }

            @Override
            public void onAnimationEnd(Animation animation) {// 此方法执行1次

                // 动画结束 隐藏控件
                tvCountDown.setVisibility(View.GONE);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {// 此方法执行4次(repeatCount值)
                tvCountDown.setText(""+count);
                count--;
            }
        });

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值