android - 帧动画不起作用

标签 android frame android-animation

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

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/

相关文章:

android - Android中如何实现羽化效果?

ios - 我的 UIButton 的位置在所有模拟器中都不同

ios - UIScreen mainScreen 边界给出错误的大小

java - ListView 中的 Admob 广告

java - 我们可以缩小所有类,但只用 proguard 混淆一些类吗?

ios - 旋转时 UIWebView 大小不正确

android - 如何在 Jetpack compose 中制作 FlipCard 动画

android - Android Lollipop 中属于不同 Activity 的 fragment 之间的共享元素转换

android - 我可以更改 Android Layout Transition 的行为以消除淡入淡出但保持高度动画吗?

android - hierarchyviewer 不工作