Inicio de la animación marco por cuadro
Tengo una pregunta básica sobre cómo iniciar una animación marco por cuadro.
Cuando llamo el método AnimationDrawable.start () desde mi código directamente, no parece funcionar.
- Cómo cargar sprite hoja con 5 filas y 5 columnas vista superior en android?
- Actualizar el diseño con la animación
- Deslice la animación expandida en android
- Animar agregar / quitar elementos de ListView con CursorAdapter es posible?
- Adaptador de actualización de animación ListView android
public void onCreate(Bundle savedInstanceState) { ... mAnimation.start(); ... }
Pero si pongo esta línea en el método de devolución de llamada onClick () de un botón, al presionar el botón se inicia la animación.
¿Por qué esta línea no funciona en el código?
¡Gracias!
Código:
public class MyAnimation extends Activity { @Override public void onCreate(Bundle savedInstanceState) { AnimationDrawable mframeAnimation = null; super.onCreate(savedInstanceState); setContentView(R.layout.my_animation); ImageView img = (ImageView) findViewById(R.id.imgMain); BitmapDrawable frame1 = (BitmapDrawable) getResources().getDrawable( R.drawable.splash1); BitmapDrawable frame2 = (BitmapDrawable) getResources().getDrawable( R.drawable.splash2); int reasonableDuration = 250; mframeAnimation = new AnimationDrawable(); mframeAnimation.setOneShot(false); mframeAnimation.addFrame(frame1, reasonableDuration); mframeAnimation.addFrame(frame2, reasonableDuration); img.setBackgroundDrawable(mframeAnimation); mframeAnimation.setVisible(true, true); //If this line is inside onClick(...) method of a button, animation works!! mframeAnimation.start(); }
}
- Actividad de visualización de abajo hacia arriba
- Animación de texto de izquierda a derecha como brillo en Android
- Error setBackground Ver después de la animación
- Rotación de la vista Jerarquía 90 grados
- Usando la lista de animación de android
- Cómo Swing imagen como péndulo en Android?
- Error al intentar probar AnimatedVectorDrawable, "No se puede cambiar de x a z"
- ¿Cómo puedo eliminar el retraso antes de una animación LayoutTransition
Es importante tener en cuenta que el método start () llamado en AnimationDrawable no se puede llamar durante el método onCreate () de su Actividad, ya que AnimationDrawable aún no está completamente conectado a la ventana. Si desea reproducir la animación de inmediato, sin requerir interacción, es posible que desee llamarla desde el método onWindowFocusChanged () de su Actividad, que se llamará cuando Android enfoque su ventana. Muy al final de la página http://developer.android.com/guide/topics/graphics/2d-graphics.html
ImageView img = (ImageView)findViewById(R.id.some layout); AnimationDrawable frameAnimation = (AnimationDrawable)img.getDrawable(); frameAnimation.setCallback(img); frameAnimation.setVisible(true, true); frameAnimation.start();
Y para agregar animación puedes hacer algo como
<animation-list android:id="@+id/my_animation" android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/frame1" android:duration="150" /> <item android:drawable="@drawable/frame2" android:duration="150" /> </animation-list>
Utilice un Runnable para insertar el mensaje start () en la cola de mensajes, simplemente agregue este LOC para reemplazar su mFrameAnimation.start ();
img.post(new Starter());
Clase interna del ayudante:
class Starter implements Runnable { public void run() { mFrameAnimation.start(); } }
Para jugar una animación sólo en onCreate (…) add:
ImageView mImageView=(ImageView) findViewById(R.id.image); mImageView.setBackgroundResource(R.anim.film); mFrameAnimation = (AnimationDrawable) mImageView.getBackground(); mImageView.post(new Runnable(){ public void run(){ mFrameAnimation.start(); } });
- ¿Podemos acceder al controlador de micrófono de mi teléfono Android
- Java.lang.OutOfMemoryError – BitmapFactory.decode (strPath)