且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

android ListView增加Animation效果

更新时间:2022-09-04 20:52:18

anim文件夹下建立anim_layout.xml和alpha.xml

-----------------------android:animationOrder 的取值有normal 0 默认reverse 1 倒序random 2 随机-----------------------

anim_layout.xml

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"  
  3.   
  4.  android:delay="0.5"  
  5.  android:animationOrder="random"  
  6.  android:animation="@anim/alpha"  
  7.  />  

alpha.xml

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  3.         android:interpolator="@android:anim/accelerate_interpolator">  
  4.           
  5.     <alpha  
  6.         android:fromAlpha="0.0"  
  7.         android:toAlpha="1.0"  
  8.         android:duration="500" />  
  9.       
  10. </set>  

布局文件里的ListView增加一个layoutAnimation属性

[java] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <ListView   
  8.         android:id="@id/android:list"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent"  
  11.         android:drawSelectorOnTop="false"  
  12.         android:layoutAnimation="@anim/anim_layout"  
  13.         ></ListView>  
  14.       
  15.     <TextView  
  16.         android:id="@id/android:empty"  
  17.         android:layout_width="fill_parent"  
  18.         android:layout_height="fill_parent"  
  19.         android:text="No data" />  
  20.       
  21. </LinearLayout>