码迷,mamicode.com
首页 > 其他好文 > 详细

ListView Animation

时间:2016-04-05 15:48:49      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

简单介绍一下4种动画效果方式

[java] view plain copy
 
  1. AnimationSet set = new AnimationSet(false);  
  2. Animation animation = new AlphaAnimation(0,1);   //AlphaAnimation 控制渐变透明的动画效果  
  3. animation.setDuration(500);     //动画时间毫秒数  
  4. set.addAnimation(animation);    //加入动画集合  
  5.   
  6. animation = new TranslateAnimation(1, 13, 10, 50);  //ScaleAnimation 控制尺寸伸缩的动画效果  
  7. animation.setDuration(300);  
  8. set.addAnimation(animation);  
  9.   
  10. animation = new RotateAnimation(30,10);    //TranslateAnimation  控制画面平移的动画效果  
  11. animation.setDuration(300);  
  12. set.addAnimation(animation);  
  13.   
  14. animation = new ScaleAnimation(5,0,2,0);    //RotateAnimation  控制画面角度变化的动画效果  
  15. animation.setDuration(300);  
  16. set.addAnimation(animation);  
  17.   
  18. LayoutAnimationController controller = new LayoutAnimationController(set, 1);  
  19.   
  20.   
  21. GridView gridView = (GridView) this.findViewById(R.id.gridview);  
  22. gridView .setLayoutAnimation(controller);  //GridView 设置动画效果  
  23.   
  24. ListView listview= (ListView)this.findViewById(R.id.listview);  
  25. listview.setLayoutAnimation(controller);   //ListView 设置动画效果  

************************************************或者***********************************************************

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>  

ListView Animation

标签:

原文地址:http://www.cnblogs.com/chenxibobo/p/5354972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!