AnimationDrawable par programmation sans animation-list xml
Je suis dans une situation où je veux afficher l'animation de liste dynamique des images. Je veux utiliser AnimationDrawable à cette fin, mais malheureusement, je suis bloqué... 🙁 mon code est comme
ImageView globe = (ImageView) findViewById(R.id.globe);
AnimationDrawable animation = new AnimationDrawable();
animation.setOneShot(true);
Resources res = this.getResources();
while (from <= to) {
String name = "globe_" + String.format("%03d", from);
int globeId = res.getIdentifier(name, "drawable",
this.getPackageName());
animation.addFrame(res.getDrawable(globeId), 200);
from++;
}
globe.setBackgroundDrawable(animation);
globe.post(new Runnable(){
@Override
public void run() {
animation.start();
}
});
source d'informationauteur makki
Vous devez vous connecter pour publier un commentaire.
Animation.addFrame(Drawable cadre, int duree) prend un drawable que vous pouvez créer à partir d'une image.
Si votre liste d'images sont chargées dynamiquement:
Essayer, devrait certainement travailler.
J'ai juste fait
animation.start()
après la boucle et a appelé la fonction à partir d'un exécutable, et il a travaillé