给ViewGroup的子元素添加出场效果

利用Android开发艺术探索的例子,实践了一下

给ViewGroup的子元素添加出场效果,遵循以下几个步骤
1.在res/anim/anim_layout中定义LayoutAnimation
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
    android:delay="0.5"
    android:animationOrder="normal"
    android:animation="@anim/anima_item"
    />


2.位子元素指定具体的入场动画
<?xml version="1.0" encoding="utf-8"?>
     android:duration="300"
     android:interpolator="@android:anim/accelerate_interpolator"
     android:shareInterpolator="true"
    >
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"/>
    <translate
        android:fromXDelta="500"
        android:toXDelta="0"/>

</set>


3.为ViewGroup指定android:layoutAnimation属性,=“@anim/anim_layout”。这种方式适用所有的ViewGroup
<ListView
    android:id="@+id/lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutAnimation="@anim/anima_layout"
    android:background="#fff4f7f9"
    android:cacheColorHint="#000"
    android:divider="#dddbdb"
    android:dividerHeight="1px"
    android:listSelector="@android:color/transparent"/>


除了在XML中指定LayoutAnimation外,还可以通过LayoutAnimationController来实现,具体的代码如下:
Animation animation= AnimationUtils.loadAnimation(this,R.anim.anima_item);
LayoutAnimationController animationController=new LayoutAnimationController(animation);
animationController.setDelay(0.5f);
animationController.setOrder(LayoutAnimationController.ORDER_NORMAL);
listview.setLayoutAnimation(animationController);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值