如何让Android按钮显示动画本身点击时 [英] How to make Android Buttons show animation on itself when clicked
问题描述
我试图让一个按钮,将发挥在pressed一个动画列表。
我已经在这里显示一个animation.xml:
< XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目机器人:可绘制=@可绘制/一机器人:时间=500/>
<项目机器人:可绘制=@可绘制/两个机器人:时间=500/>
<项目机器人:可绘制=@可绘制/三机器人:时间=500/>
<项目机器人:可绘制=@可绘制/四机器人:时间=500/>
< /动画列表>
也为onClick的功能:
b_button.setBackgroundResource(R.drawable.animation);
AnimationDrawable frameAnimation =(AnimationDrawable)b_button.getBackground();
frameAnimation.setOneShot(真正的);
frameAnimation.start();
当我preSS按钮,动画会播放,但是,对于只有一次,以后当我preSS它的时候,它不会玩。此外,我该如何改变按钮回到它的原始状态?含义灰色默认外观的按钮。
任何帮助是AP preciated, 在此先感谢
如果(frameAnimation.isRunning()){
frameAnimation.stop();
} 其他 {
frameAnimation.stop();
frameAnimation.start();
}
尝试为这个工程(与单稳,无单稳)?动画将停止在最后一帧,这样你就可以添加一个在XML其中可绘为灰色默认外观 THX:)
I'm trying to make a Button that will play a animation-list when pressed.
I have made a animation.xml shown here:
<?xml version="1.0" encoding="UTF-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/one" android:duration="500" />
<item android:drawable="@drawable/two" android:duration="500" />
<item android:drawable="@drawable/three" android:duration="500" />
<item android:drawable="@drawable/four" android:duration="500" />
</animation-list>
Also for the onClick function:
b_button.setBackgroundResource(R.drawable.animation);
AnimationDrawable frameAnimation = (AnimationDrawable) b_button.getBackground();
frameAnimation.setOneShot(true);
frameAnimation.start();
When I press the button, the animation would be played, however, for just once, after when I press it the second time, it will not play. Furthermore, how do I change the button back to it's original state? Meaning the grey default look of the button.
Any help is appreciated, Thanks in advance
if (frameAnimation.isRunning()) {
frameAnimation.stop();
} else {
frameAnimation.stop();
frameAnimation.start();
}
try is this works(with OneShot and without OneShot)? The animation will stop at last frame, so you can add a in xml which drawable is the grey default look thx :)
这篇关于如何让Android按钮显示动画本身点击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!