Android学习之界面篇(三)LayoutAnimationController详细介绍
来源:互联网 发布:mac os10.13锐捷 编辑:程序博客网 时间:2024/05/20 03:07
在前面学习了Android学习之界面篇(一)Android Animation简单使用和 Android学习之界面篇(二)Android AnimationSet简单使用的简单使用,但是这些动态效果只适应一个控件,或者说多个控件同时执行一种效果。如果我们需要一个界面中的多个控件按照相同的动画方式但是每个控件完成该动画的时刻不同的话,就可采用本节讲的LayoutAnimationController来方便的完成了。
LayoutAnimationController介绍:
- LayoutAnimationController用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果(即整个布局)
- 每一个控件都有相同的动画效果
- 这些控件的动画效果可在不同的时间显示出来
Android官方定义:
Class Overview
A layout animation controller is used to animated a layout's, or a view group's, children. Each child uses the same animation but for every one of them, the animation starts at a different time. A layout animation controller is used by ViewGroup
to compute the delay by which each child's animation start must be offset. The delay is computed by using characteristics of each child, like its index in the view group. This standard implementation computes the delay by multiplying a fixed amount of miliseconds by the index of the child in its parent view group. Subclasses are supposed to override getDelayForView(android.view.View)
to implement a different way of computing the delay. For instance, aGridLayoutAnimationController
will compute the delay based on the column and row indices of the child in its parent view group. Information used to compute the animation delay of each child are stored in an instance of LayoutAnimationController.AnimationParameters
, itself stored in the ViewGroup.LayoutParams
of the view.
LayoutAnimationController可以在xml文件当中设置,也可以在代码中进行设置
本文就针对两种实现LayoutAnimationController的方法分别进行介绍:
- xml配置
由于layout-animation是对于某一组控件的操作,就需要一个基本的动画来定义单个控件的动画。另外还可以定义动画的显示顺序和延迟:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"android:delay="30%"android:animationOrder="reverse"android:animation="@anim/slide_right"/>
android:delay表示动画播放的延时,既可以是百分比,也可以是float小数。
android:animationOrder表示动画的播放顺序,有三个取值normal(顺序)、reverse(反序)、random(随机)。
android:animation指向了子控件所要播放的动画。
android:layoutAnimation=
"@anim/list_anim_layout"
这样在加载布局的时候就会自动播放layout-animtion。
- 代码配置
LinearLayout rootView= (LinearLayout) findViewById(R.id.linearLayout);ScaleAnimation sa=new ScaleAnimation(0,1,0,1);//缩放效果sa.setDuration(5000);LayoutAnimationController lac=new LayoutAnimationController(sa,2f);//dalay为延时lac.setOrder(LayoutAnimationController.ORDER_RANDOM);//设置部件出现顺序rootView.setLayoutAnimation(lac);
本例实现界面如下:
- Android学习之界面篇(三)LayoutAnimationController详细介绍
- Android动画之LayoutAnimationController
- Android动画之LayoutAnimationController(五)
- Android动画之LayoutAnimationController(五)
- Android动画之LayoutAnimationController(五)
- android学习——LayoutAnimationController 和 ViewGroup
- LayoutAnimationController -- MarsChen Android 开发教程学习笔记
- Android Animations之LayoutAnimationController的使用方法
- Android Animations之LayoutAnimationController的使用方法
- Android学习之界面篇(一)Android Animation简单介绍
- android 学习教程(三)之---工程目录结构介绍
- iOS学习之路(三)--界面篇
- Android之高仿微信“登录界面”(三)
- XCode主界面之导航区域介绍(三)
- LayoutAnimationController源码深入学习
- Android动画-LayoutAnimationController
- Android学习之界面篇(九)SurfaceView简单学习
- Android学习之界面篇(六)ViewPager学习与Android引导界面的实现
- 创客空间
- 排序方法
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- JSON数据解析
- Tomcat 部署详解
- Android学习之界面篇(三)LayoutAnimationController详细介绍
- 【千里码】访客统计
- C++ advance
- git版本管理
- LCD电子书项目(四)
- Android焦点分发基本流程
- 第五周项目(3)-设计游戏角色(2)-析构函数
- 如何获得即时编译器(JIT)的汇编代码(linux环境下)
- 封闭类、友元、this指针、常量对象