gpt4 book ai didi

android - 帧动画不起作用

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

我正在开发我想同时运行两帧动画的应用程序,但它不起作用....我的代码如下....

ImageView Background, planet, info;
AnimationDrawable infoview, backgroundview;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Background = (ImageView) findViewById(R.id.imageView1);
planet = (ImageView) findViewById(R.id.planet);
//Background.setImageResource(R.drawable.friend_night_sky_31000);
Log.w("debug", "planetanimation started");
planetStart(R.drawable.earth, R.drawable.background);
Log.w("debug", "planetanimation stoped");
info = (ImageView) findViewById(R.id.info);
info.setImageResource(R.drawable.earthinfo);
Log.w("DEBUG", "which is null:image " + infoview + "or" + backgroundview);
}

public void planetStart(final int pid, final int bid){
Thread timer = new Thread(){
@Override
public void run(){
try{
//Thread.sleep(time);
} catch (Exception e){

} finally{
Infoview.this.runOnUiThread(new Runnable(){
public void run(){
planet.setBackgroundResource(pid);
infoview = (AnimationDrawable) planet.getBackground();
infoview.start();
Background.setBackgroundResource(bid);
backgroundview = (AnimationDrawable) Background.getBackground();
backgroundview.start();
Log.w("DEBUG", "which is null:image " + infoview + "or" + backgroundview);
}
});
}
}
};
timer.start();
}

谁能帮我解释为什么它不起作用?

Edit1我的地球文件如下

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item android:drawable="@drawable/earthframe1" android:duration="150" />
<item android:drawable="@drawable/earthframe2" android:duration="150" />
<item android:drawable="@drawable/earthframe3" android:duration="150" />
<item android:drawable="@drawable/earthframe4" android:duration="150" />
<item android:drawable="@drawable/earthframe5" android:duration="150" />
<item android:drawable="@drawable/earthframe6" android:duration="150" />
<item android:drawable="@drawable/earthframe7" android:duration="150" />
<item android:drawable="@drawable/earthframe8" android:duration="150" />
<item android:drawable="@drawable/earthframe9" android:duration="150" />
</animation-list>

bg文件如下

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false">
<item android:drawable="@drawable/bg_1" android:duration="150" />
<item android:drawable="@drawable/bgimage2" android:duration="150" />
<item android:drawable="@drawable/bgimage03" android:duration="150" />
<item android:drawable="@drawable/bgimage4" android:duration="150" />
<item android:drawable="@drawable/bgimage5" android:duration="150" />


</animation-list>

最佳答案

您有两种解决方案,您可以从 planetStart 方法中删除线程,或者如果您想使用现有代码而不是提供一些值,例如 Thread.sleep(1000); 在线程 sleep 中我已经检查了这个值并且它对我还有一件事避免在第一个动画结束之前开始第二个动画

关于android - 帧动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154412/

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