简介

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. 开始编写正式的iOS 程序(iOS编程指导)

    App设计基础 在确定了你的App主要功能后,需要把它转化为代码.如果你是第一次开发属于自己的iOS App,需要花些时间熟悉基本概念.iOS内置了很多设计样式,多了解下能对你以后有帮助. 初稿 设计 ...

  2. bash shell学习-正则表达式基础 (笔记)

    A gentleman is open-minded and optimistic; a small person is narrow-minded and pessimistic. "君子 ...

  3. js中callee与caller的区别

    callee是对象的一个属性,该属性是一个指针,指向参数arguments对象的函数首先我们来写个阶成函数:function chen(x){if (x<=1) {return 1;} else ...

  4. mysql hash索引优化

    创建表 CREATE TABLE `t1` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `msg` varchar(20) NOT NULL DEFAULT ' ...

  5. saas系统架构经验总结

    2B Saas系统最近几年都很火.很多创业公司都在尝试创建企业级别的应用 cRM, HR,销售, Desk Saas系统.很多Saas创业公司也拿了大额风投.毕竟Saas相对传统软件的优势非常明显. ...

  6. MVC中的模型注解

    authour: chenboyi updatetime: 2015-04-26 21:28:42 friendly link:   目录: 1,思维导图 2,内容解析 3,CodeSimple 1, ...

  7. insert 和 if x is not None

    insert(位置,元素) #!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print &qu ...

  8. python处理mysql慢查询日志

    # -*- coding:utf8 -*- ''' Created on 2017年1月9日 @author: qiancheng ''' import re import os from email ...

  9. 记 tower.im 的一次重构

    原文in here: http://outofmemory.cn/wr?u=http%3A%2F%2Fblog.mycolorway.com%2F2013%2F05%2F01%2Ftower-refa ...

  10. Unity脚本获取内存和FPS

    using System; using System.Collections.Generic; using UnityEngine; public class Debugger : MonoBehav ...