简介

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. LXPanel自定义添加应用程序到快速启动栏

    LXPanel是Linux下LXDE项目的一个桌面面板软件.我一开始接触的时候,对于自己自定义的程序到快速启动栏绕了很多弯路,这里记录下,防止以后自己忘了.还有一点就是很多时候,panel下的应用程序 ...

  2. sql server 利用首字母拼音排序和笔画排序的语句

    --按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...

  3. os mac apache+php+mysql环境配置

    1.启用系统自带的apache 服务 打开终端(terminal) #sudo apachectl start #sudo vi /etc/apache2/httpd.conf 修改 LoadModu ...

  4. 【leetcode】1. Two Sums

    题目 https://leetcode.com/problems/two-sum/   Given an array of integers, find two numbers such that t ...

  5. IOS--UIActivityIndicatorView的使用方法详细

    IOS--UIActivityIndicatorView的使用方法详细   // UIActivityIndicatorView的常用方法 活动指示器,就是旋转进度轮 UIActivityIndica ...

  6. 『GitHub』Git常用命令记录

    Commands: git init 把当前目录变成Git可以管理的仓库 随后出现.git目录,这个目录是Git来跟踪管理版本库的git commit -m "change message& ...

  7. How to Install Linux, Apache, MySQL, PHP (LAMP) stack on CentOS 6 【Reliable】

    About LAMP LAMP stack is a group of open source software used to get web servers up and running. The ...

  8. 【2013杭州区域赛】部分题解 hdu4770—4780

    1008: 题意: 有20W个数,每个数都在20W以内,现在有20W个询问,每次询问L,R区间内不会打架的数有多少个 定义两个数不互质 就会打架 解法: 脑洞很大的一道题,先要进行预处理,对每一个数预 ...

  9. Controlling How NSThread and NSRunLoop Exit

    http://shaheengandhi.com/controlling-thread-exit/ While most concurrency can be dealt with by using ...

  10. @Resource 和 @Autowired注解的异同

    @Resource 和 @Autowired注解的异同 @Autowired 默认按类型装配,默认情况下必须要求依赖对象必须存在,如果要允许null值,可以设置它的required属性为false 例 ...