gpt4 book ai didi

android - 在动画中使用 5-6 个线程是个好主意吗?

转载 作者:行者123 更新时间:2023-11-30 04:26:34 26 4
gpt4 key购买 nike

我使用 5-6 个线程一次显示一个动画。我使用的是平移动画和帧动画。这是一个好主意吗?最好的方法是什么?我的代码在下面给出。

Handler handler1 = new Handler();        
handler1.postDelayed(new Runnable() {
public void run() {
Animation animation = new TranslateAnimation(0 ,0 ,0 ,100 );
animation.setDuration(800);
ImageView rimg2 = (ImageView) findViewById(R.id.rainfall);
animation.setRepeatCount(-1);
rimg2.startAnimation(animation);

Animation animation1 = new TranslateAnimation(-290, 290,0, -150);
animation1.setDuration(35000);
ImageView rimg = (ImageView) findViewById(R.id.cloud1);
rimg.setVisibility(View.VISIBLE);
animation1.setRepeatCount(-1);
rimg.startAnimation(animation1);
}
},0);

Handler handler2 = new Handler();
handler2.postDelayed(new Runnable() {
public void run() {
Animation animation = new TranslateAnimation(0 ,0 ,0 ,100 );
animation.setDuration(800);
ImageView rimg3 = (ImageView) findViewById(R.id.drops);
animation.setRepeatCount(-1);
rimg3.startAnimation(animation);
rimg3.setVisibility(View.VISIBLE);
}
},1000);

Handler handler3 = new Handler();
handler3.postDelayed(new Runnable() {
public void run() {
Animation animation = new TranslateAnimation(0 ,0 ,-250 ,10 );
animation.setDuration(800);
ImageView rimg2 = (ImageView) findViewById(R.id.rainfall1);
animation.setRepeatCount(-1);
rimg2.startAnimation(animation);
rimg2.setVisibility(View.VISIBLE);
}
},5000);

Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
public void run() {
Animation animation = new TranslateAnimation(0 ,0 ,-150 ,10 );
animation.setDuration(800);
ImageView rimg3 = (ImageView) findViewById(R.id.drops1);
animation.setRepeatCount(-1);
rimg3.startAnimation(animation);
rimg3.setVisibility(View.VISIBLE);
}
},10000);

Handler handler5 = new Handler();
handler5.postDelayed(new Runnable() {
public void run() {
Animation animation1 = new TranslateAnimation(-290, 290,0, -150);
animation1.setDuration(35000);
ImageView rimg = (ImageView) findViewById(R.id.cloud2);
rimg.setVisibility(View.VISIBLE);
animation1.setRepeatCount(-1);
rimg.startAnimation(animation1);
}
},15000);

最佳答案

除非您的代码示例中没有显示原因,否则您不需要发布 Runnables 来运行这些动画。您可以从主 UI 线程启动动画。有关详细信息,请查看此处的文档:

http://developer.android.com/guide/topics/graphics/view-animation.html

这里

http://developer.android.com/reference/android/view/animation/Animation.html

如果您想错开动画开始时间,您还可以设置 StartOffset。

如果你想在动画结束时做一些事情,你可以使用Animation.setAnimationListener

关于android - 在动画中使用 5-6 个线程是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8383051/

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