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.
- Android - Animar el diálogo emergente con efecto de rebote
- Vista de Android que desaparece cuando se sale de los padres
- Efecto de desplazamiento con múltiples visualizadores
- Animación de una vista mientras que ListView no está funcionando
- Animación de carga de línea 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(); }
}
- Fragmento de Android Elementos compartidos que no funcionan con "agregar"
- La animación de vista de Android se detiene al salir de la pantalla
- Transición de elemento compartido entre fragmentos que pertenecen a diferentes actividades en Android lollipop
- Animación de Android una tras otra
- Animación giratoria androide
- RecyclerView - No hay animación en NotifyItemInsert
- Ocultar vista con animación y establecer visibilidad a desaparecer sin flash en la pantalla
- Actualizar el diseño con la animación
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)