单击一个按钮时,我想实现一个alpha动画。
动画是:Alpha从1降到0.5,当它到达0.5时又从0.5降到1。循环这两个动画。我该怎么做?可以在文件/res/anim
夹的xml文件中定义它,还是必须使用AnimationListener
?
谢谢
您可以使用一个简单的AlphaAnimation
对象来执行此操作。将重复模式设置为,setRepeatMode(Animation.REVERSE)
以将alpha从0.5更改为1.0,并setRepeatCount(count)
重复次数。
动画XML示例:
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.5"
android:duration="1000" />
加载xml的代码:
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
a.reset();
a.setRepeatMode(Animation.REVERSE);
a.setRepeatCount(5); // will be infinite if -1
Button btn = (Button ) findViewById(R.id.btn);
btn.clearAnimation();
btn.startAnimation(a);
代码只是一个示例。希望这行得通。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句