简介

http://blog.csdn.net/pipisky2006/article/details/8317091

补间动画只能对一个控件使用,如果要对某一组控件播放一样的动画的话,可以考虑layout-animation。
  • LayoutAnimationController用于为一个LinearLayout等布局里面的控件或者是ListView等的item设置动画效果
  • 布局中每一个控件都会有相同的动画效果
  • 这些动画效果在不同的时间显示出来
  • LayoutAnimationController不仅可以在Layout里面实现也可以在代码中实现

布局中使用

1、在res/anim下新建一个普通的XML补间动画

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="500"
        android:fromAlpha="0"
        android:toAlpha="1" />
    <rotate
        android:duration="500"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" />

</set>

2、在res/anim下新建一个 layoutAnimation 动画

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"

<!-- 其中delay的单位为秒;animation为设置动画的文件。animationOrder为子控件进入的方式 -->

    android:animation="@anim/anim_set"
    android:animationOrder="random"
    android:delay="0.5" >

</layoutAnimation>

3、在需配置动画的布局文件中为控件添加 android:layoutAnimation 属性:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:layoutAnimation="@anim/layout_anim"
    android:orientation="vertical" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是文字我是文字我是文字" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:src="@drawable/ic_launcher" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我是文字我是文字我是文字" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

</LinearLayout>


代码中使用

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LinearLayout lLayout = (LinearLayout) findViewById(R.id.ll);
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_set);//也可以在代码中直接使用补间动画!
        LayoutAnimationController lac = new LayoutAnimationController(animation);
        lac.setOrder(LayoutAnimationController.ORDER_NORMAL);//设置控件显示的顺序;
        lac.setDelay(1);//设置控件显示间隔时间,注意单位是秒;
        lLayout.setLayoutAnimation(lac);
    }

}


布局动画 LayoutAnimation的更多相关文章

  1. Android动画效果之自定义ViewGroup添加布局动画

    前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...

  2. Android中的布局动画

    简介 布局动画是给布局的动画,会影响到布局中子对象 使用方法 给布局添加动画效果: 先找到要设置的layout的id,然后创建布局动画,创建一个LayoutAnimationController,并把 ...

  3. 自定义ViewGroup添加布局动画

    声明几个属性值: <declare-styleable name="GridImageViewGroup"> <attr name="childVert ...

  4. UI设计篇·入门篇·简单动画的实现,为布局设置动画,用XML布置布局动画

    不仅仅控件可以设置动画,一个布局也可以设置动画, 当给一个布局设置了动画的时候,这个布局里所包含的控件都会依赖执行这些动画. 为布局设置动画的实现步骤: 1.新建一个动画,设置需要实现的形式 2.新建 ...

  5. Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画

    前言: 之前,我已经写了两篇博文,给大家介绍了Android的基础动画是如何实现的,如果还不清楚的,可以点击查看:Android Animation动画详解(一): 补间动画 及 Android An ...

  6. Android Animation学习(五) ApiDemos解析:容器布局动画 LayoutTransition

    Android Animation学习(五) ApiDemos解析:容器布局动画 LayoutTransition Property animation系统还提供了对ViewGroup中的View改变 ...

  7. android 属性动画和布局动画p165-p171

    一.属性动画 ObjectAnimator ObjectAnimator是属性动画框架中最重要的实行类,创建一个ObjectAnimator只需通过他的静态工厂类直接返回一个ObjectAnimato ...

  8. React Native超棒的LayoutAnimation(布局动画)

          该文翻译自:https://medium.com/@Jpoliachik/react-native-s-layoutanimation-is-awesome-4a4d317afd3e#.6 ...

  9. AndroidUI 布局动画-为列表添加布局动画效果

    新建一个Android project ,使MainActivity 继承自 ListActivity: public class MainActivity extends ListActivity ...

随机推荐

  1. js学习笔记之:时间(二)

    今天来了解一下js中定时器的两种用法.js中包括2种定时器,分别是:           间隔型定时器:setInterval(开)    clearInterval (关)            延 ...

  2. PAT - IO-01. 表格输出(5)

    题目: 本题要求编写程序,按照规定格式输出表格. 输入格式: 本题目没有输入. 输出格式: 要求严格按照给出的格式输出下列表格: ----------------------------------- ...

  3. oracle常用SQL总结

    这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收 ...

  4. 如何用angularjs制作一个完整的表格之四__自定义ng-model标签的属性使其支持input之外的html元素

    有的时候我们需要为非input类型的元素添加ng-model来实现双向的数据绑定,从而减少冗余代码,那么可以尝试一下的方式 例如:我页面中使用了contenteditable这个属性来实现用户可直接编 ...

  5. thinkphp框架之模型(数据库查询)

    1. 模型定义 文件名称必须是 表名+Model.class.php 例如:UserModel.class.php namespace Home\Model; //该模型类的命名空间 use Thin ...

  6. PHP文章管理

    功能说明:  文章的基本操作:添加,修改,锁定,解锁,推荐,删除等待  并有强大功能的搜索,评论,推荐给朋友等功能,并对安全性进行着重加强,漂亮的界面人性化的设计.  主要文件列表:  setup.p ...

  7. django HttpRequest

    request.path 除域名以外的请求路径,以正斜杠开头 "/hello/" request.get_host() 主机名(比如,通常所说的域名) "127.0.0. ...

  8. C# ORM—Entity Framework 之Code first(代码优先)(二)

    一.Entity Framework Code first(代码优先)使用过程 1.1Entity Framework 代码优先简介 不得不提Entity Framework Code First这个 ...

  9. 关于 wait_event_interruptible() 和 wake_up()的使用

    来源:http://blog.csdn.net/allen6268198/article/details/8112551 1. 关于 wait_event_interruptible() 和 wake ...

  10. 常用排序算法之——快速排序(C语言+VC6.0平台)

    经典排序算法中快速排序具有较好的效率,但其实现思路相对较难理解. #include<stdio.h> int partition(int num[],int low,int high) / ...