android中的animations的用法(三)

一 LayoutAnimationController 的使用方法

二 ListView 与Animations 结合使用

三 AnimationListener 的使用方法



介绍LayoutAnimationController ,这个类相当重要,它可以增强用户体验.

LayoutAnimationController 用于为一个layout 里面的控件,或者是一个ViewGroup里面的控件设置动画效果

可以在xml文件中设置,也可以在java类中设置

第一种方法: 在xml文件设置

1. 在res/anim 文件夹中他建一个新文件,名为list_anim_layout.xml文件:

<layoutAnimation xmlns:android=http://schemas.android.com/apk/res/android"

android:delay="0.5" android:animationOrder="random" android:animation="@anim/list_anim" />

在0.5表示0.5秒,不再是0.5毫秒

2.在布局文件中为ListView添加如下配置 android:layoutAnimation="@anim/list_anim_layout"










第二种方法: 在java类中使用 LayoutAnimationController

1. 创建一个Animation对象: 可以通过装载xml文件,或者直接使用Animation 的构造函数创建Animation对象;

2. 使用如下代码创建LayoutAnimationController 对象: LayoutAnimationController lac = new LayoutAnimationController(animation);



3. 设置控件显示的顺序: lac.setOrder(LayoutAnimationController.ORDER_NORMAL);

4. 为ListView 设置LayoutAnimationController 属性: listView.setLayoutAnimation(lac);



具体代码请参考:layoutAnimationsTest 工程

---------------------------

关于AnimationListener

AnimationListener 是一个监听器,该监听器在动画执行的各个阶段会得到通知,从而调用相应的方法

主要包括以下三个方法

onAnimationEnd(Animation animation)

onAnimationRepeat(Animation animation)

onAnimationStart(Animation animation)



具体代码请参考: animationListenerTest 工程
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值