Android的Animation之LayoutAnimation使用方法
来源:互联网 发布:智诚轮胎软件 编辑:程序博客网 时间:2024/05/17 03:00
LayoutAnimationController用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果,可以在XML文件中设置,亦可以在Java代码中设置。
一种直接在XML文件中设置
1. 在res/anim文件夹下新建一个XML文件,名为list_anim_layout.xml,
- <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
- android:delay="30%"
- android:animationOrder="reverse"
- android:animation="@anim/slide_right" />
android:delay 子类动画时间间隔 (延迟) 70% 也可以是一个浮点数 如“1.2”等
android:animationOrder="random" 子类的显示方式 random表示随机
android:animationOrder 的取值有
normal0 默认reverse1 倒序random2 随机android:animation="@anim/slide_right" 表示孩子显示时的具体动画是什么
2. 在res/anim文件夹下新建一个XML文件,名为slide_right,即上面用到的文件。
- <set xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@android:anim/accelerate_interpolator">
- <translate android:fromXDelta="-100%p" android:toXDelta="0"
- android:duration="@android:integer/config_shortAnimTime" />
- </set>
显示的效果为ListView第一次出现的时候为 item随机出现 每个Item都是从左不可见(-100%p)的区域向右滑动到显示的地方
3. 在主布局文件中为控件添加如下配置:
android:layoutAnimation="@anim/list_anim_layout",即第一步的布局文件。
第二种设置方法:在Java代码中设置
1. 同上;
2. 同上;
4. 在Acitivty中添加如下代码:
//通过加载XML动画设置文件来创建一个Animation对象;
Animation animation=AnimationUtils.loadAnimation(this, R.anim.list_anim);
//得到一个LayoutAnimationController对象;
LayoutAnimationController lac=new LayoutAnimationController(animation);
//设置控件显示的顺序;
lac.setOrder(LayoutAnimationController.ORDER_REVERSE);
//设置控件显示间隔时间;
lac.setDelay(1);
//为ListView设置LayoutAnimationController属性;
datalist.setLayoutAnimation(lac);
//-----------------------------------------------------------------------------------------------------------------------------------
推荐文章
Android中给listview/gridview设置动画(逐条加载条目动画)
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法
- Android的Animation之LayoutAnimation使用方法(控件设置动画)
- Android 动画之LayoutAnimation
- Android动画之LayoutAnimation
- Android动画三部曲之一 View Animation & LayoutAnimation
- android之Animation使用方法二
- Android layoutanimation的应用
- Android动画效果之:LayoutAnimation
- 安卓动画系列之二,补间动画(Tween Animation)以及动画结合LayoutAnimation的好处
- Android Animation 动画的使用方法和介绍
- Android Animation 动画的使用方法和介绍
- Android Animation 动画的使用方法和介绍
- Android小记:Animation的Interpolator使用方法
- 双向链表的基本操作
- 简单的log4j
- LevelDb 阅读遇到的问题记录
- c语言中函数指针与指针函数的区别
- unity3d开源Ultimate MMORPG插件技术文档渣翻译第4页
- Android的Animation之LayoutAnimation使用方法
- available bandwidth paper(2)
- java基础——构造函数小知识点
- ios内存管理
- 运行时runbime
- Ubuntu 14.04 搭建Android开发环境 (转载)
- hdu 4352 - XHXJ's LIS (数位dp)多校联合
- 类的友元类的说明
- Android打电话