Android控制gridview或listview中子控件的动画LayoutAnimation

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());

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值