以编程方式为ViewSwitcher设置动画

sel*_*chi 3 android android-animation 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" >
Run Code Online (Sandbox Code Playgroud)

我怎么能以编程方式做同样的事情?

Luk*_*rog 10

请阅读该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);
Run Code Online (Sandbox Code Playgroud)