动画二(LayoutAnimator)

LayoutAnimator,这个动画是作用在viewGroup包含的子控件的。也就是给ViewGroup的子控件做动画。
比如给ListView中的item做动画。
下面看看LayoutAnimation动画在xml文件中的通用配置:

<?xml version="1.0" encoding="utf-8"?>

<layoutAnimation xmlns:android=“http://schemas.android.com/apk/res/android”
android:duration=“integer”
android:delay=“float”
android:animationOrder=[“normal”|“reverse”|“random”]
android:animation="@anim/animation_test">

<!--android:animationOrder="normal" 表示子元素的动画顺序,有三个选项,normal,reverse和random-->
<!--random,其中normal表示顺序显示,即排在前面的子元素先开始放入场动画-->
<!--reverse表示逆向开始,即排在后面的子元素先开始播放入场动画-->
<!--random表示子元素随机播放入场动画。-->
<!--android:animation="@anim/具体animation文件名称" 表示为子元素指定入场动画-->
下面具体给出一个使用layoutAnimation的示例: 1.首先创建一个子view的动画,在anim目录下,新建一个animation_item.xml的文件,其中的配置信息如下: <?xml version="1.0" encoding="utf-8"?>
  <translate android:fromXDelta="0"
      android:toXDelta="50"
      android:fromYDelta="0"
      android:toYDelta="50">
  </translate>
2.创建layoutAnimation文件,在anim目录下,新建一个layout_animation_test.xml文件。配置信息如下: <?xml version="1.0" encoding="utf-8"?>


<!--android:animationOrder="normal" 表示子元素的动画顺序,有三个选项,normal,reverse和random-->
<!--random,其中normal表示顺序显示,即排在前面的子元素先开始放入场动画-->
<!--reverse表示逆向开始,即排在后面的子元素先开始播放入场动画-->
<!--random表示子元素随机播放入场动画。-->

<!--android:animation="@anim/animation_item" 表示为子元素指定入场动画-->

3.完成上面的layoutAnimation后,就可以使用了。下面这个示例是将layoutAnimation动画作用到ListView的item条目上。具体,只要设置android:layoutAnimation="@anim/layout_animation_test" 即可

进过这三步,就完成了给ListView的item添加动画的效果。
一般能够通过xml来配置动画效果的,代码也能实现,下面用代码方式完成上面步骤3的过程。
ListView lv = (ListView) findViewById(R.id.lv);
Animation layoutAnimation = AnimationUtils.loadAnimation(this,R.anim.animation_item);
LayoutAnimationController controller = new LayoutAnimationController(layoutAnimation);
controller.setDelay(0.5f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
lv.setLayoutAnimation(controller);
lv.setAdapter(mAdapter);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值