需求:执行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--;            }        });

 

更多相关文章

  1. android中TextView图文混排
  2. Android中的多线程
  3. 布局与控件(三)-TextView那些事儿
  4. Android(安卓)App开发基础篇—Android(安卓)Studio的基本使用
  5. Android:充电状态、轮询、电池状态、Notification
  6. android:targetSdkVersion问题。
  7. Android(安卓)materialDesign 风格阴影 改变阴影颜色
  8. Android(安卓)软键盘弹出,界面整体上移
  9. Android画图学习总结(四)——Animation(下)

随机推荐

  1. Android多线程并发访问网络
  2. Android+ELK 实现实时日志功能
  3. android,wp7后台程序运行区别
  4. 解决Android(安卓)Studio 新建导入项目时
  5. Android:常用知识篇之 EditText和输入法
  6. 从0开始在Android下开发生活方向盘应用(自
  7. android与模式:解耦与复用
  8. Android的屏幕刷新原理
  9. Android(安卓)SDK 离线安装详细教程[2012
  10. 鲍尔默炮轰Android难用:用户须是计算机专