本文主要是介绍LayoutAnimationController -- MarsChen Android 开发教程学习笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
LayoutAnimationController 的使用方法用于为一个Layout 里面的控件,或者是一个ViewGroup 里面的空间设置动画效果,能够一次性为一个Activity 设置动画效果,每个空间都有相同的动画效果,但是可以在不同时间显示出来。
1、在res 文件夹中创建一个新文件夹,再新的文件架下创建一个新xml文件抓们控制LayoutAnimationController,Animation 属性要另外新建一个。添加<layoutAnimation >标签
<span style="white-space:pre"> </span><?xml version="1.0" encoding="utf-8"?><layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="0.5"android:animationOrder="normal"android:animation="@anim/list_anim"/>
android:delay 代表间隔多长时间.android:animationOrder 代表动画执行的顺序random 是随机,nomal 是顺序,reverse 是倒叙。
2、在布局文件中为ListView 添加命令行
android:layoutAnimation="@anim/list_anim_layout"
如果在一个空间的父控件设置,那么这个父控件的所有子控件都会拥有相同的动画属性。
3、创建一个适配器,并放入数据供ListView 使用。
4、跟之前ListView 一样,最后又要调用setAdapter 方法。
5、如果不在布局文件中添加ListView 添加步骤2 的命令行,可在JAVA 代码中如下设置。
<span style="white-space:pre"> </span>class ButtonListener implements OnClickListener{@Overridepublic void onClick(View v) {listView.setAdapter(buildListAdapter());Animation animation = (Animation)AnimationUtils.loadAnimation(MainActivity.this, R.anim.list_anim);LayoutAnimationController animationController = new LayoutAnimationController(animation);animationController.setOrder(LayoutAnimationController.ORDER_NORMAL);listView.setLayoutAnimation(animationController);}}
这篇关于LayoutAnimationController -- MarsChen Android 开发教程学习笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!