Pergunta

Eu configurei a animação no layout assim:

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

Como posso fazer o mesmo programaticamente?

Foi útil?

Solução

Por favor, leia a documentação do ViewSwitcher classe, ela possui dois métodos para configurar a animação de entrada/saída:

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

Outras dicas

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

Você pode pular a etapa de carregamento da animação com AnimationUtils e, em vez disso, passe o recurso anim diretamente:

switcher.setInAnimation(this, android.R.anim.slide_in_left);
switcher.setOutAnimation(this, android.R.anim.slide_out_right);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top