2012-07-08 9 views
6

ich so mit AnimationDrawable:AnimationDrawable funktionieren nicht in Android 2.2

ImageView rocketImage = (ImageView) layout.findViewById(R.id.animation); 
rocketImage.setBackgroundResource(R.drawable.progress_blue_animation); 
rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 
rocketAnimation.start(); 

Dieser Code Arbeit in Android 3.0/4.0/4.1/4.0, aber funktionieren nicht in Android 2.2. Wie man dieses Problem löst?

Antwort

17

Soweit ich weiß, das ist ein Bug in 2.1, 2.2

Eine mögliche Abhilfe könnte:

ImageView rocketImage = (ImageView) layout.findViewById(R.id.animation); 
rocketImage.setBackgroundResource(R.drawable.progress_blue_animation); 
rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 
rocketImage.post(new Runnable(){ 
    public void run(){ 
     rocketAnimation.start(); 
    } 
}); 

(Aber ich es nicht versucht in Targets> 2.1)

+1

getestet mit Android 4.0, es funktioniert gut und danke. –

+2

Danke, funktioniert wie Charme. –

+3

Ich möchte eine Lade-Animation mit einem Popup-Fenster anzeigen. Eigentlich funktioniert es auf 4.0 aber nicht auf 2.3.3. Ich habe viele Dinge ausprobiert, wie zum Beispiel einen anderen Thread, eine Post-Methode usw. Nichts hat das Problem gelöst. Auf 2.3.3 zeigt es nur das erste Bild. Wie könnte dies gelöst werden? –

0
view.post(new Runnable() { 
     public void run() { 
      anim.start(); 
     } 
    }); 
    view.startAnimation(anim); 

das funktioniert für mich.