我正在使用以下代码为我的 SplashScreen 设置 2 个图像之间的动画:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// Show A Transitions for Splash image here.
TransitionDrawable transition = (TransitionDrawable) getResources()
.getDrawable(R.drawable.splash_animation);
//Set interval for the transition between two image.
transition.startTransition(5000);
//Fetch imageView from your layout and apply transition on the same.
ImageView imageView= (ImageView) findViewById(R.id.splash_image);
imageView.setImageDrawable(transition);
}
我的 splash.xml 是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:scaleType="fitXY"
android:id="@+id/splash_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/img_1" />
</RelativeLayout>
我的 splash_animation.xml 文件是:
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/img_1"></item>
<item android:drawable="@drawable/img_2"></item>
</transition>
过渡工作正常,但我想知道是否也可以为 3 个图像创建它。我尝试在 splash_animation 中添加第三张图像,但仅对第一张图像进行过渡。我怎样才能为我想要的尽可能多的图像实现它?