res/anim/anim_layout.xml:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:animation="@anim/anim_train" android:animationOrder="normal" android:delay="0.5"> </layoutAnimation>
res/anim/anim_train.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300"> <translate android:fromXDelta="500" android:toXDelta="0"/> </set>然后在ListView中添加
android:layoutAnimation="@anim/anim_layout"例如:
<ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_red_dark" android:layoutAnimation="@anim/anim_layout" android:cacheColorHint="#00000000" android:divider="#dddbdb" android:dividerHeight="1.0px" android:listSelector="@android:color/transparent" />layoutAnimation 是作用于ViewGroup ,为ViewGroup指定一个动画,这样当它的子元素出场时都会具有这种动画效果,这种效果常常被用在ListView上,我们时常会看到一种特殊的ListView,它的每个item都以一定的动画形式出现,其实这病非什么高深的技术,它使用的就是LayoutAnimation.LayoutAnimation也是一个View动画,
它几个属性的含义:
android:delay ->表示子元素开始动画的时间延迟,比如子元素入场动画的时间周期为300ms,那么0.5表示每个子元素都需要延迟150ms才能入场动画,
android:animationOrder ->表示子元素动画的顺序,有三种,normal,reverse,random.其中normal表示顺序显示,即排在前面的子元素先开始播放入场动画:reverse表示逆向显示,即排在后面的子元素先开始播放入场动画;random则是随机播放入场动画。
android:animation ->为子元素指定具体的入场动画。