我的平板应用程序只有一个活动和几个不同的布局,用于不同的UI模式 - 每个布局都使用<fragment>标记来使用不同的片段填充UI(在Activity中调用setContentView以切换模式)。
我该如何使用转换动画来淡入新的片段,当它们被这种方式加载时?目前,在模式之间切换会产生闪烁效果,因为片段正在加载。
谢谢!
我的平板应用程序只有一个活动和几个不同的布局,用于不同的UI模式 - 每个布局都使用<fragment>标记来使用不同的片段填充UI(在Activity中调用setContentView以切换模式)。
我该如何使用转换动画来淡入新的片段,当它们被这种方式加载时?目前,在模式之间切换会产生闪烁效果,因为片段正在加载。
谢谢!
我以前从未使用过片段(fragments),但是拥有片段不会影响我的解决方案。基本上,您需要在某个布局的第一个层次上实现要显示的动画效果。最好的例子是Listview。
首先,您需要添加一些额外的动画文件,这些文件添加到res/anim中。
layout_controller.xml:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="@anim/bounce" />
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator">
<translate
android:fromXDelta="40%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="900"/>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000"
android:interpolator="@android:anim/linear_interpolator"
/>
这个动画会让物品弹入并淡入。
如果你有一个列表视图,在它的XML中设置这个(对于TextView、ImageView等也适用)。
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:persistentDrawingCache="animation|scrolling"
android:layoutAnimation="@anim/layout_controller"
/>