2012-09-29 24 views
3

我設置這樣的佈局動畫:爲ViewSwitcher集動畫編程

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

我怎麼可以這樣做編程?

回答

9

請閱讀ViewSwitcher類的文檔,它有設定輸入/輸出動畫兩種方法:

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

謝謝。它正在工作。 –

+0

保存我的一天.... –

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