Question

J'ai défini l'animation dans la mise en page comme ceci :

<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" >

Comment puis-je faire la même chose par programme ?

Était-ce utile?

La solution

Veuillez lire la documentation du ViewSwitcher classe, il dispose de deux méthodes pour définir l’animation d’entrée/sortie :

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

Autres conseils

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

Vous pouvez sauter l'étape de chargement de l'animation avec AnimationUtils et à la place, transmettez directement la ressource anim :

switcher.setInAnimation(this, android.R.anim.slide_in_left);
switcher.setOutAnimation(this, android.R.anim.slide_out_right);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top