我创建了一个由ViewSwitcher组成的广告控件.
在这个控件中,我有ImageView和TextView,因为广告要么是文本,要么是图像。
现在我要给这些进步注入动画。
我已经试过了
动画inAnimation =AnimationUtils.loadAnimation(本文,android.R.anim.slide_in_left);inAnimation.setDuration(1500);
动画outAnimation =AnimationUtils.loadAnimation(此处,android.R.anim.slide_out_right);outAnimation.setDuration(1500);
我把它设置为
ViewSwitcher交换机;
switcher.setInAnimation(inAnimation);
switcher.setOutAnimation(outAnimation);
但这行不通..。
请给我其他的选择。或者如果使用上述代码是错误的,那么如何使用呢??
发布于 2012-06-08 18:53:17
尝试将xml中的动画设置为
<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" >发布于 2014-12-02 03:55:13
此外:
负责switcher.showNext();或switcher.showPrevious();
如果将动画设置为开关程序,则两个操作都将导致相同的动画。
发布于 2019-10-23 04:39:21
正如问题所述,我现提出另一项选择。使用它,您将实现与ViewPager相同的动画。
您可以将showNext设置为1,而不是displayedChild。
switcherView?.inAnimation = AnimationUtils.loadAnimation(baseActivity, R.anim.slide_in_right)
switcherView?.outAnimation = AnimationUtils.loadAnimation(baseActivity, R.anim.slide_out_left)
switcherView?.displayedChild = 1可以将showPrevious设置为0,而不是displayedChild。
switcherView?.inAnimation = AnimationUtils.loadAnimation(baseActivity, R.anim.slide_in_left)
switcherView?.outAnimation = AnimationUtils.loadAnimation(baseActivity, R.anim.slide_out_right)
switcherView?.displayedChild = 0动画文件: R.anim.slide_in_right:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>R.anim.slide_out_left
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>R.anim.slide_in_left
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0" />
</set>R.anim.slide_out_right
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>每次设置displayedChild时,都需要设置动画。如果你不想要动画,你可以忽略它,仅此而已。编码愉快!
PS: Kotlin代码
https://stackoverflow.com/questions/10532141
复制相似问题