android 简单快速 倒计时动画
16lz
2021-12-04
需求:执行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--; } });
更多相关文章
- android中TextView图文混排
- Android中的多线程
- 布局与控件(三)-TextView那些事儿
- Android(安卓)App开发基础篇—Android(安卓)Studio的基本使用
- Android:充电状态、轮询、电池状态、Notification
- android:targetSdkVersion问题。
- Android(安卓)materialDesign 风格阴影 改变阴影颜色
- Android(安卓)软键盘弹出,界面整体上移
- Android画图学习总结(四)——Animation(下)