是的,我可以用2张图片创建ToggleButton (开,关),但是我想要创建一个3-5图片的ToggleButton。
例如,何时关闭,我单击:
它什么时候开着,我点击:
因此,它就像框架动画,我可以使用与持续时间与ImageView。
发布于 2013-09-25 15:25:58
编辑:
您可以使用帧动画:In res/drawable/myanim.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pic_one" android:duration="50"/>
<item android:drawable="@drawable/pic_two" android:duration="50" />
<item android:drawable="@drawable/pic_three" android:duration="50" />
</animation-list>然后,您可以将此动画用作普通绘图:
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/myanim"/>要启动动画,请执行以下操作
AnimationDrawable backgroundDrawable = (AnimationDrawable) image.getDrawable();
backgroundDrawable.start();您还可以使用价值动画。我还没有对此进行测试,但是您应该能够将类似的内容放入您按钮的onClick处理程序中:
int[] backgrounds = ...;//ids of the backgrounds for the button
ValueAnimator anim = ValueAnimator.ofInt(0, backgrounds.length);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int i = (Integer) animation.getAnimatedValue();
int backgroundId = backgrounds[i];
yourButton.setBackgroundResource(backgroundId);
}
});
anim.setDuration(500); //0.5 seconds
anim.start();https://stackoverflow.com/questions/19008555
复制相似问题