默认情况下,ViewGroup中的子视图是直接显示出来的,为viewgroup添加动画,分为代码引入和xml引用,下面介绍为listview添加动画效果
二步走:
1声明anim文件,如layout_list.xml定义动画
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="20%" android:animationOrder="normal" android:animation="@anim/list_layout"/>
2.在listview xml中引用:
android:layoutAnimation="@anim/layout_list"
或者代码调用:
Animation animation = AnimationUtils.loadAnimation(this, R.anim.layout_list); LayoutAnimationController controller = new LayoutAnimationController(animation, 0.5f); listView.setLayoutAnimation(controller);