我以前从未使用过片段,但没有任何理由说明片段会影响我的解决方案。基本上,您实现了一个动画以显示在某物的第一个布局上。最好的例子是列表视图
首先,您需要添加几个额外的动画文件,添加到 res/anim
layout_controller.xml:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="50%"
android:animation="@anim/bounce" />
这定义了一个布局的过程。
然后,bounce.xml
<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"
/>
layoutAnimation 字段告诉列表视图参考布局控制器如何显示列表视图。当listview第一次被绘制时,每个item都应该依次反弹进来。你可以通过改变bounce.xml轻松自定义动画,或者通过改变layout_controller中定义的50%延迟来改变等待时间。