Android AnimationDrawable在返回主屏幕时停止

时间:2011-10-19 11:59:52

标签: java android xml android-animation

我正在Android中开发一款游戏,其中启动器屏幕上有2个AnimationDrawables。

动画可以一起运行,但是当我离开屏幕然后回击以返回它时,其中一个动画停止,另一个继续。

我的代码如下:

  static AnimationDrawable animation;
  static AnimationDrawable animation2;
 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

animation = new AnimationDrawable();
  animation.addFrame(getResources().getDrawable(R.drawable.j0), 200);
  animation.addFrame(getResources().getDrawable(R.drawable.j1), 200);
  animation.addFrame(getResources().getDrawable(R.drawable.j2), 200);
  animation.addFrame(getResources().getDrawable(R.drawable.j3), 200);
  animation.setOneShot(false);

  animation2 = new AnimationDrawable();
  animation2.addFrame(getResources().getDrawable(R.drawable.logo), 250);
  animation2.addFrame(getResources().getDrawable(R.drawable.logo1), 250);
  animation2.setOneShot(false);

ImageView imageAnim =  (ImageView) findViewById(R.id.imageView1);
  imageAnim.setBackgroundDrawable(animation);
  imageAnim.post(new MenuAnimate());

 ImageView imageAnima =  (ImageView) findViewById(R.id.imageView2);
      imageAnima.setBackgroundDrawable(animation2);
      imageAnima.post(new MenuAnimate2());


class MenuAnimate implements Runnable {

public void run() {
    Menu.animation.start();
}
}

class MenuAnimate2 implements Runnable {

public void run() {
    Menu.animation2.start();
}
}

Xml'菜单':

   <LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="wrap_content" android:weightSum="1" android:layout_weight="0.93">
     <ImageView android:id="@+id/imageView1" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
     <ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="bottom"></ImageView>
</LinearLayout>

如果有人有任何想法,那就太棒了。

0 个答案:

没有答案