本篇博客主要介绍如何通过animation和LayoutAnimation来实现ListView的item显示动画。实现ListView中的item显示动画需要注意,这种动画只会在ListView第一次加载item的时候起作用,在之后的item重新绘制等一系列情况都不会起作用!!!这一点需要注意,确定是否符合你的需求!!!
先看一下效果图吧:
看一下主布局文件吧(其实没什么好看的,就是一个listview):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layoutAnimation="@anim/list_layout_animation"
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
list_animation_1.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<translate
android:fromXDelta=