1. 组件动画

设置ViewGrouplayoutAnimation属性,指定组件动画配置。

android:layoutAnimation="@anim/anim_layout_animation"

配置属性

  • delay,动画播放延迟时间
  • animationOrder,子控件播放动画顺序。animationOrder的值为normalreverserandom
  • animation,指定补间动画

组件动画anim_layout_animation.xml文件

补间动画anim_in_from_right.xml文件

效果如下
Android 组件动画_第1张图片

2. 代码实现

LayoutAnimationController可以实现组件动画。

Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_in_from_right);LayoutAnimationController controller = new LayoutAnimationController(animation);controller.setDelay(0.1f);controller.setOrder(LayoutAnimationController.ORDER_NORMAL);ViewGroup container = findViewById(R.id.container);container.setLayoutAnimation(controller);container.startLayoutAnimation();

3. 指定播放顺序

自定义LayoutAnimationController,并覆盖getTransformedIndex(AnimationParameters)方法,同时指定自定义顺序setOrder(-1)

private static class CustomLayoutAnimationController extends LayoutAnimationController {    CustomLayoutAnimationController(Animation animation) {        super(animation);    }    @Override    protected int getTransformedIndex(AnimationParameters params) {        if (getOrder() < 0) {            int index = params.index;            int count = (params.count + 1) / 2;            if (index < count) {                return count - 1 - params.index;            } else {                return params.index - count;            }        } else {            return super.getTransformedIndex(params);        }    }}

效果如下
Android 组件动画_第2张图片
相关文章
Animation动画
帧动画
属性动画
组件动画
Transition动画

更多相关文章

  1. Android buttom textview 颜色平滑过渡的动画效果
  2. Android用户界面UI组件--AdapterView及其子类(三) ExpandableLis
  3. Android布局动画之animateLayoutChanges与LayoutTransition
  4. Android 属性动画 源码解析 深入了解其内部实现
  5. Android 开发笔记 动画效果 --Animation
  6. android中动画的使用

随机推荐

  1. 我的android 第8天 - 单元测试
  2. Android之防火墙功能的实现
  3. Android与HTML+JS交互入门
  4. 细谈Android应用架构
  5. Android网络请求心路历程
  6. Android(安卓)设置投影效果
  7. Android知识体系结构概览
  8. 用cmd 命令更改Android(安卓)的默认虚拟
  9. Android横竖屏切换总结
  10. 微信小程序性能分析Trace工具