android layoutAnimation属性简单介绍与使用

时间:2024-04-05 07:21:54

简单介绍

layoutAnimation来源于ViewGroup中的属性,主要功能是实现ViewGroup中子控件开始显示的动画效果,简单方便的实现layout中的控件动画实现

用法

layoutAnimation有两种用法

一.xml属性配置


<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/linear_layout_animation_item_time"/>

二.代码块实现


LayoutAnimationController animationController=AnimationUtils.loadLayoutAnimation(context, R.anim.linear_layout_animation_item_time);
setLayoutAnimation(animationController);

从上面可以看出实现方式是不是很简单,只需要一句xml属性或者两句代码就可以配置子控件动画

三.动画属性配置说明

在res/anim 中新建layoutAnimation的动画属性
linear_layout_animation_item_time配置如下

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/item_time_start"
android:animationOrder="normal"
android:delay="25%">
<!--
android:animation="@anim/item_time_start" : 具体实现方式
android:animationOrder="normal" :
可以选择三种类型:normal, reverse random。它控制内容动画的顺序。
Normal:遵循direction和delay所定义的顺序;
Reverse的顺序恰好跟Normal相反;
Random为随机的顺序。
android:delay="15%" :
动画延迟,总长时间15%
-->
</layoutAnimation>

item_time_start简单配置如下

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600">
<translate
android:fromXDelta="-100%p"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="0" />
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>

效果如下

这是一个简单recyclerView出现的动画
android layoutAnimation属性简单介绍与使用