gpt4 book ai didi

机器人过渡

转载 作者:太空狗 更新时间:2023-10-29 14:25:05 25 4
gpt4 key购买 nike

我正在使用以下代码为我的 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 是:

<?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 中添加第三张图片,但只对第一张图片进行了转换。我怎样才能为尽可能多的图像实现它?

最佳答案

放入 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]);

关于机器人过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13284221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com