Android AnimationDrawable останавливается после возврата на главный экран - PullRequest
1 голос
/ 19 октября 2011

Я разрабатываю игру для 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>

Если у кого-либо есть идеиэто было бы удивительно.

...