LayoutAnimation是控制gridview和listview中item的动画## 标题
1.属性:
LayoutAnimation从布局写动画:xml
LayoutAnimation从java代码写动画:LayoutAnimationController
2.写法:
从布局写的话,直接在res文件中新建anim文件再在里面新建动画的xml文件,然后在相应的gridview或listview中使用,关键代码android:layoutAnimation="@anim/XXX"

动画的主要代码属性介绍
1.android:delay(子元素开始的动画的时间延迟)
2.android:animation(子元素具体的入场动画)
3.android:animationorder(子元素动画顺序)
用java代码写的话,这里列举一个动画
public static LayoutAnimationController getgridlayoutAnim() {
int duration = 300;
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(duration);
set.addAnimation(animation);
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(duration);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
controller.setOrder(LayoutAnimationController.ORDER_REVERSE);
return controller;
}
然后在获取的gridview或listview中直接调用
gridView.setLayoutAnimation(getgridlayoutAnim());
138

被折叠的 条评论
为什么被折叠?



