Android LayoutAnimation

首先在res/anim目录下新建sweep_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toAlpha="1.0" />

    <translate
        android:duration="1000"
        android:fromXDelta="100%"
        android:interpolator="@android:anim/bounce_interpolator"
        android:toXDelta="0" />

</set>

然后同理创建layout_swipe_in.xml

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/sweep_in"
    android:animationOrder="random"
    android:delay="10%" />
    
android:delay  子类动画时间间隔延迟 20% | 1.2
android:animationOrder="random" 
子类的显示方式
normal	 0	   默认
reverse	 1	   倒序
random	 2	   随机
android:animation="@anim/slide_right" 表示子项显示动画

为视图设置效果

  1. xml方式

android:layoutAnimation="@anim/layout_swipe_in"

2.代码方式

//通过加载XML动画设置文件来创建一个Animation对象;
Animation animation=AnimationUtils.loadAnimation(this, R.anim.swipe_in);
//得到一个LayoutAnimationController对象;
LayoutAnimationController lac=new LayoutAnimationController(animation);
//设置控件显示的顺序;
lac.setOrder(LayoutAnimationController.ORDER_REVERSE);
//设置控件显示间隔时间;
lac.setDelay(200);
//为ListView设置LayoutAnimationController属性;
listview.setLayoutAnimation(lac);


你可能感兴趣的:(Android LayoutAnimation)