android过渡
我正在使用以下代码为我的SplashScreen设置两个图像之间的动画:android过渡,android,android-animation,android-image,Android,Android Animation,Android Image,我正在使用以下代码为我的SplashScreen设置两个图像之间的动画: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); // Show A Transitions for Splash image here. TransitionDrawable transition
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_动画中添加第三个图像,但仅对第一个图像进行了转换。我怎样才能为我想要的尽可能多的图像实现它呢?将
TransitionDrawable的数组放入其中
List<TransitionDrawable>array = new ArrayList<TransitionDrawable>();
TransitionDrawable transition1 = (TransitionDrawable) getResources()
.getDrawable(R.drawable.splash_animation1); // first,second image
TransitionDrawable transition2 = (TransitionDrawable) getResources()
.getDrawable(R.drawable.splash_animation2); // third,fourth image
array.add(transition1);
array.add(transition2);
// call array
for(TransitionDrawable transition :array){
transition.start(5000);
}
ImageView imageView= (ImageView) findViewById(R.id.splash_image);
imageView.setImageDrawable(transition[0]); // if transition[0] is finished setImageDrawable(transition[1]);
listary=newarraylist();
TransitionDrawable transition1=(TransitionDrawable)getResources()
.getDrawable(R.drawable.splash_animation1);//第一、第二图像
TransitionDrawable transition2=(TransitionDrawable)getResources()
.getDrawable(R.drawable.splash_animation2);//第三、第四形象
add(transition1);
add(transition2);
//调用数组
for(TransitionDrawable transition:array){
过渡。启动(5000);
}
ImageView ImageView=(ImageView)findViewById(R.id.splash_图像);
imageView.setImageDrawable(转换[0]);//如果转换[0]已完成,则设置ImageDrawable(转换[1]);
您可以对任意数量的图像执行此操作
您需要使用数组中的当前项和下一项重新创建TransitionDrawable并对其进行更新
请参见我在foreach(事务:数组)转换中的回答。startTransition(5000);