Domanda

Imposta l'animazione nel layout come questa:

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

Come posso fare lo stesso programmaticamente?

È stato utile?

Soluzione

Leggere la documentazione per la classe ViewSwitcher, ha due metodi per l'impostazione dell'animazione IN / OUT:

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

Altri suggerimenti

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

È possibile saltare la fase del caricamento dell'animazione con AnimationUtils e passare invece direttamente la risorsa anim:

switcher.setInAnimation(this, android.R.anim.slide_in_left);
switcher.setOutAnimation(this, android.R.anim.slide_out_right);
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top