zoukankan      html  css  js  c++  java
  • [Android Pro] Android的Animation之LayoutAnimation使用方法

    用于为一个里面的控件,或者是一个里面的控件设置动画效果,可以在文件中设置,亦可以在代码中设置。

    一种直接在XML文件中设置

    1.  res/anim文件夹下新建一个XML文件,名为list_anim_layout.xml,

        <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"  
                android:delay="30%"  
                android:animationOrder="reverse"  
                android:animation="@anim/slide_right" />  

    android:delay  子类动画时间间隔 (延迟)   70% 也可以是一个浮点数 如“1.2”等

    android:animationOrder="random"   子类的显示方式 random表示随机

    android:animationOrder 的取值有 

    normal 0    默认
    reverse 1   倒序
    random 2   随机

    android:animation="@anim/slide_right" 表示孩子显示时的具体动画是什么


    说明:其中delay的单位为秒;animation为设置动画的文件。animationOrder为进入方式

    2.  res/anim文件夹下新建一个XML文件,名为slide_right,即上面用到的文件。

            <set xmlns:android="http://schemas.android.com/apk/res/android"   
                android:interpolator="@android:anim/accelerate_interpolator">  
            <translate android:fromXDelta="-100%p" android:toXDelta="0"  
                    android:duration="@android:integer/config_shortAnimTime" />  
        </set>  
        <set xmlns:android="http://schemas.android.com/apk/res/android"   
                android:interpolator="@android:anim/accelerate_interpolator">  
            <translate android:fromXDelta="-100%p" android:toXDelta="0"  
                    android:duration="@android:integer/config_shortAnimTime" />  
        </set>  

     显示的效果为ListView第一次出现的时候为 item随机出现 每个Item都是从左不可见(-100%p)的区域向右滑动到显示的地方

    3.  在主布局文件中为控件添加如下配置:

    android:layoutAnimation="@anim/list_anim_layout",即第一步的布局文件。

     

     

    第二种设置方法:在Java代码中设置

     

    1. 同上;

     

    2. 同上;

     

    4.  Acitivty中添加如下代码:

     


     

    //通过加载XML动画设置文件来创建一个Animation对象;

     

           Animation animation=AnimationUtils.loadAnimation(this, R.anim.list_anim);

     

           //得到一个LayoutAnimationController对象;

     

           LayoutAnimationController lac=new LayoutAnimationController(animation);

     

           //设置控件显示的顺序;

     

           lac.setOrder(LayoutAnimationController.ORDER_REVERSE);

     

           //设置控件显示间隔时间;

     

           lac.setDelay(1);

     

           //ListView设置LayoutAnimationController属性;

     

       datalist.setLayoutAnimation(lac);

     

  • 相关阅读:
    [Codeforces 339D] Xenia and Bit Operations
    [Codeforces 459D] Pashmak and Parmida's problem
    [Codeforces 460C] Present
    [Codeforces 466C] Number of Ways
    [Codeforces 650A] Watchmen
    Linux系统中‘dmesg’命令处理故障和收集系统信息的7种用法
    select函数详解
    都是stm32的JTAG引脚惹的祸
    uboot中的快捷菜单的制作说明
    卷积的本质及物理意义(全面理解卷积)
  • 原文地址:https://www.cnblogs.com/0616--ataozhijia/p/3904674.html
Copyright © 2011-2022 走看看