Pregunta

Configuré la animación en el diseño de esta manera:

<ViewSwitcher
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:inAnimation="@android:anim/slide_in_left"
    android:outAnimation="@android:anim/slide_out_right" >

¿Cómo puedo hacer lo mismo mediante programación?

¿Fue útil?

Solución

Por favor lea la documentación del ViewSwitcher clase, tiene dos métodos para configurar la animación de entrada/salida:

// load the two animations  
Animation animIn = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
Animation animOut = AnimationUtils.loadAnimation(context, android.R.anim.slide_out_right);
// set them on the ViewSwitcher
vs.setInAnimation(animIn);
vs.setOutAnimation(animOut);

Otros consejos

viewswitcher.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in));
viewswitcher.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out));

Puedes omitir el paso de cargar la animación con AnimationUtils y en su lugar pasa el recurso anim directamente:

switcher.setInAnimation(this, android.R.anim.slide_in_left);
switcher.setOutAnimation(this, android.R.anim.slide_out_right);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top