Android 倒计时动画
今天给大家分享一个可以用来做倒计时的动画....下期开始准备写几篇动画的详细解释,毕竟授人以鱼不如授人以渔
接下来还是先上效果图
熟悉动画的人相信心中已经有了想法。。其实这个动画就是Alpha动画和Scale动画结合在一起
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" /> <scale android:duration="800" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:toXScale="0.5" android:toYScale="0.5" /> </set>
这是用set使俩个动画同时运行,如果想要依次的话,可以使用startOffset
private TextView textView; private Animation animation; private Animation animation2; private int count = 30; private Button btnSwitch; private int flag = 0; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView) findViewById(R.id.text); animation = AnimationUtils.loadAnimation(this, R.anim.animation_text2); animation2 = AnimationUtils.loadAnimation(this, R.anim.animation_text); btnSwitch = (Button) findViewById(R.id.btn_switch); btnSwitch.setOnClickListener(this); textView.startAnimation(animation); handler.sendEmptyMessageDelayed(0, 1000); } public void small() { animation2.reset(); textView.startAnimation(animation2); } public void big() { animation.reset(); textView.startAnimation(animation); } private int getCount() { count--; if (count < 0 || count > 30) { count = 30; } return count; } Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { if (msg.what == 0) { textView.setText("" + getCount()); handler.sendEmptyMessageDelayed(0, 1000); small(); } else { textView.setText("" + getCount()); handler.sendEmptyMessageDelayed(1, 1000); big(); } }; }; @Override public void onClick(View arg0) { switch (flag) { case 0: handler.removeMessages(0); handler.sendEmptyMessageDelayed(1, 1000); flag = 1; break; case 1: handler.removeMessages(1); handler.sendEmptyMessageDelayed(0, 1000); flag = 0; break; default: break; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。