Android LayoutAnimation
2015-12-01 18:11
507 查看
LayoutAnimation作用于ViewGroup,为ViewGroup指定一个动画,这样当它的子元素出场时都会具有该动画效果,这种效果通常被用在ListView中,下面以一个例子说明:
首先在anim中创建一个layoutanimation:
android:delay 子类动画时间间隔 (延迟),如果动画周期为1000ms,标示第一个动画会延迟500ms开始播放入场动画,第二个元素也是如此,以此类推。这里的50% 也可以是一个浮点数 如“0.5”等
android:animationOrder 表示子元素动画的顺序,有三种选项:normal,reverse和random,其中normal是默认选项,标示顺序显示;reverse 标示逆向显示;random则是随机播放入场动画
android:animation 表示显示时的具体动画,本例中动画如下:
其中对ListView的设置如下:
除了通过xml中指定的LayoutAnimation外,还可以通过LayoutAnimationController来实现,具体代码如下:
首先在anim中创建一个layoutanimation:
[code]<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:animationOrder="normal" android:animation="@anim/list_anim" android:delay="50%"> </layoutAnimation>
android:delay 子类动画时间间隔 (延迟),如果动画周期为1000ms,标示第一个动画会延迟500ms开始播放入场动画,第二个元素也是如此,以此类推。这里的50% 也可以是一个浮点数 如“0.5”等
android:animationOrder 表示子元素动画的顺序,有三种选项:normal,reverse和random,其中normal是默认选项,标示顺序显示;reverse 标示逆向显示;random则是随机播放入场动画
android:animation 表示显示时的具体动画,本例中动画如下:
[code]<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:duration="1000" android:fromAlpha="0.5" android:toAlpha="1"></alpha> <translate android:duration="1000" android:fromXDelta="-200" android:toXDelta="0" /> </set>
其中对ListView的设置如下:
[code] <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layoutAnimation="@anim/listview" android:layout_height="match_parent"></ListView>
除了通过xml中指定的LayoutAnimation外,还可以通过LayoutAnimationController来实现,具体代码如下:
[code]LayoutAnimationController control = AnimationUtils.loadLayoutAnimation(context, id); //设置控件显示的顺序 control.setOrder(LayoutAnimationController.ORDER_REVERSE); //设置控件显示间隔时间; control.setDelay(1); //为ListView设置LayoutAnimationController属性; listView.setLayoutAnimation(lac);
相关文章推荐
- Android EditText 软键盘上回车改为搜索
- android手电筒
- Android利用WebSocket进行实时通讯
- Android keystore相关
- Android 内部存储和外部存储
- Android - Activities (几种状态的切换)(2015.12.1)
- Android通过Url传递数据,实现分享功能
- Android学习笔记之Activity间传递参数
- Android service服务用法案例
- 打通Android、IOS、ANE制作流程
- Android(1)
- <4>Android4.2 G-Sensor工作流程
- Android加载动画
- Android getevent / sendevent的用法
- Android 各种设计模式
- android 计时器
- Android ScrollView自动滑动一段距离的问题解决
- <2>Android4.4——传感器初始化流程
- 重读《Kotlin For Android》一
- [Android] 简单的状态机实现