1.首先定义每个item的动画效果 在res目录下创建anim目录创建以下文件list_anim.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:shareInterpolator="true" > <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set> |
2.为ListView创建动画文件list_anim_layout.xml
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="2" android:animationOrder="normal" android:animation="@anim/list_anim"/> |
3.在布局文件中为ListView添加动画
<!-- android:layoutAnimation="@anim/list_anim_layout" 这句话是添加列表控件的动画,也可以在代码中实现 --> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" android:layoutAnimation="@anim/list_anim_layout"/> |
4.在代码中为ListView添加动画效果(我一般是在代码中添加,布局中设置的我来回刷新导致只能在第一次进入时有动画效果,直接在代码中设置就解决这个问题了,如果有发现原因的麻烦告知学习下),以下代码放在adapter刷新之前就行:
|