View动画的特殊使用----LayoutAnimation的使用

本文详细介绍了如何使用布局动画(LayoutAnimation)为ViewGroup指定动画,包括动画的延迟、顺序和具体入场动画的设置。以ListView为例,展示了如何在XML文件中和通过代码实现布局动画,并附上实际效果演示。

layoutAnimation作用于viewGroup,为ViewGroup制定一个动画,他的每个子元素都会按照这种动画出场。

首相定义LayoutAnimation如下所示:

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"  
        android:delay="0.5" 
        android:animationOrder="reverse"  
        android:animation="@anim/animation_scale" /> 

android:delay             表示子元素开始动画的时间延迟。

android:animationOrder         表示动画播放的顺序呢

               normal:顺序显示

               reverse:表示逆向显示

               random:随机播放

android:animation        为每个子元素指定具体的入场动画,如下

<?xml version="1.0" encoding="utf-8"?>
<!-- 从0.1放大到1.5 -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="0.1"
    android:toXScale="1.5"
    android:fromYScale="0.1"
    android:toYScale="1.5"
    android:duration="2000"
    >
</scale>

最后为GroupView指定LayoutAnimation属性,以listview为例:

    <ListView 
        
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/xlv"
        android:layoutAnimation="@anim/animation_layout"
        android:background="#fff4f7f9"
        android:divider="#ddd"
        android:dividerHeight="1.0px"
        android:listSelector="#999"
        ></ListView>

除了在XML文件中进行设置,我们还可以使用代码来完成:

		Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation_scale);
		LayoutAnimationController controller = new LayoutAnimationController(animation);
		controller.setDelay(0.5f);
		controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
		xlv.setLayoutAnimation(controller);

效果如下


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值