ViewSwitcher用のアニメーションをプログラムで設定します
-
11-12-2019 - |
質問
このようなレイアウトでアニメーションを設定します。
<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);
. 所属していません StackOverflow