Android的过渡 [英] android transition
本文介绍了Android的过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的code设置2图像之间的动画闪屏我:
I am using the following code to set an animation between 2 images for my SplashScreen:
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是:
My splash.xml is :
<?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文件是:
My splash_animation.xml file is :
<?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加入第三图像但过渡仅用于第一图像完成。我怎样才能实现它尽可能多的图像,我想要什么?
The transition is working fine but I wanted to know if it is possible to create it for 3 images as well. I tried adding a third image in splash_animation but the transition is only done for the first image. How can I achieve it for as many images as I want?
推荐答案
把数组的 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]);
这篇关于Android的过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文