lixplor / android-Q-A

🐞 android related questions and answers
0 stars 0 forks source link

ListView等列表出现和隐藏按条目顺序执行动画 #80

Closed lixplor closed 7 years ago

lixplor commented 7 years ago

ListView等列表出现和隐藏按条目顺序执行动画

如:

lixplor commented 7 years ago

使用LayoutAnimation可以实现一组组件的动画, 通过delay设置各自的动画的延迟

可以使用2种方式创建:

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="30%"
        android:animationOrder="reverse"
        android:animation="@anim/slide_right"/>

android:layoutAnimation="@anim/list_anim_layout"
Animation animation=AnimationUtils.loadAnimation(this, R.anim.slide_right);   //得到一个LayoutAnimationController对象;
LayoutAnimationController controller = new LayoutAnimationController(animation);   //设置控件显示的顺序;
controller.setOrder(LayoutAnimationController.ORDER_REVERSE);   //设置控件显示间隔时间;
controller.setDelay(0.3);   //为ListView设置LayoutAnimationController属性;
listView.setLayoutAnimation(controller);
listView.startLayoutAnimation();

通过动画的order设置动画播放的顺序, 可以实现组件动画播放顺序的定制