Android之Animations的高级使用

LayoutAnimationController的作用:

A.  用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果

B. 每一个控件都有相同的动画效果

C. 这些控件的动画效果在不用的时间显示出来

 

在xml当中使用LayoutAnimationController的具体步骤:

1. 在res/anim文件夹当中创建一个新文件,名为list_anim_layout.xml(自定义名字)文件:以下是例子

<layoutAnimation

xmlns:android="http://schemas.android.com/apk/res/android"

android:delay="0.5"

android:animationOrder="random"

android:animation="@anim/list_anim" />

2. 在布局文件当中为使用动画的ListView添加如下配置,:

android:layoutAnimation="@anim/list_anim_layout" 

 

在代码当中使用LayoutAnimationController

1. 创建一个Animation对象:可以通过装载xml文件(AnimationUtils.loadAnimation),或者直接使用Animation的构造函数创建Animation对象

2. 使用如下代码创建LayoutAnimationController对象:LayoutAnimationController lac = new LayoutAnimationController(animation);

3. 设置控件显示的顺序:lac.setOrder(LayoutAnimationController.ORDER_NORMAL);

4. 为ListView设置LayoutAnimationController属性:listView.setLayoutAnimation(lac); 

posted on 2012-05-22 15:03  lee0oo0  阅读(310)  评论(0编辑  收藏  举报