質問

このようなレイアウトでアニメーションを設定します。

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

どのようにプログラム的にも同じことができますか?

役に立ちましたか?

解決

ViewSwitcherクラスのマニュアルを読んでください。イン/アウトアニメーションを設定するための2つの方法があります。

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

他のヒント

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

AnimationUtilsを使用してアニメーションをロードする手順をスキップすることができ、代わりにAnim Resourceを直接渡すことができます。

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top