我正在开发一个 Android 应用程序,我需要制作一个按钮动画。
我有两个不同的图像按钮,我想要设置按钮的背景,这两个图像以 500 毫秒的延迟交替,总共只有 2 秒。
我怎样才能做到这一点并让程序在运行时等待动画结束?
我的按钮有背景和文本。我想要这个顺序:单击按钮 ->警报对话框 ->如果是,退出对话框 ->调用动画(所有 Activity 等待这个动画) ->在动画结束时调用另一个函数并继续程序
问候
最佳答案
将以下 xml 放入名为“frame”的可绘制对象中(例如,frame0 和 frame1 是两个不同的图像)
<animation-list android:id="@+id/my_animation"
android:oneshot="true" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/frame0" android:duration="500" />
<item android:drawable="@drawable/frame1" android:duration="500" />
<item android:drawable="@drawable/frame0" android:duration="500" />
<item android:drawable="@drawable/frame1" android:duration="500" />
</animation-list>
将以下代码放入您的布局 xml
<ImageButton
android:id="@+id/imageView"
android:src="@drawable/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
在 oncreate() 方法中使用以下代码
ImageButton img = (ImageButton)findViewById(R.id.imageView);
AnimationDrawable frameAnimation = (AnimationDrawable)img.getDrawable();
frameAnimation.setCallback(img);
frameAnimation.setVisible(true, true);
frameAnimation.start();
关于java - Android按钮闪烁动画与不同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10843575/