2012-04-13 11 views
12

Estoy en una situación en la que quiero mostrar la animación de la lista dinámica de imágenes. Quiero usar AnimationDrawable para este fin, pero por desgracia estoy atascado ... :(mi código es elAnimationDrawable programmatically without animation-list xml

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(); 
     } 
}); 

Respuesta

5

que acabo de hacer animation.start() faet r el bucle y se llama a la función desde un ejecutable y funcionó

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); 

animation.start() 
5

Así Animation.addFrame (marco Disponibles, duración int) toma un estirable que se puede crear a partir de una . mapa de bits

Si su lista de imágenes se cargan de forma dinámica:.

List<Bitmap> images; 
int duration = 200;  

for(Bitmap image: images){ 
    BitmapDrawable frame = new BitmapDrawable(image); 
    animation.addFrame(frame, duration); 
} 

probar esto, definitivamente debe trabajar

+0

Gracias por su respuesta, pero yo ya estoy añadiendo el dibujable través animation.addFrame (res.getDrawable (globeId), 200); e intenté tu camino también, pero no tuve suerte :( – makki

+0

Disculpa, echa un vistazo a esta frase y dime cómo va: http://androidforums.com/application-development/11620-programmatic-frame-frame -animation-examle-animationdrawable.html –