zoukankan      html  css  js  c++  java
  • LayoutAnimation-容器动画

    1.LayoutAnimation的作用主要就是加载到一个layout上,让这个layout里面的所有控件都有相同的动画效果。现在用到的是在listview中添加动画,使得它每一个item都是滑落显示

    首先看一下在代码中的实现方法,代码如下

    import android.view.animation.Animation;
    import android.view.animation.AnimationSet;
    import android.view.animation.AnimationUtils;
    import android.view.animation.RotateAnimation;
    import android.view.animation.LayoutAnimationController;
    
    
        private Animation myHistoryAnimation;
        private LayoutAnimationController myLayoutControl;
    
    myHistoryAnimation = (Animation) AnimationUtils.loadAnimation(
                    this, R.anim.history_clear_anim);
            myLayoutControl = new LayoutAnimationController(myHistoryAnimation);
            myLayoutControl.setDelay(0.4f);
            //myLayoutControl.setOrder(LayoutAnimationController.ORDER_NORMAL);
            myLayoutControl.setOrder(LayoutAnimationController.ORDER_REVERSE);
    
    
    mHistoryDisplayList.setLayoutAnimation(myLayoutControl);

    2,其中history_clear_anim.xml内容如下

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
            android:interpolator="@android:anim/accelerate_interpolator"
            android:shareInterpolator="true" >
    
            <alpha
                    android:duration="1000"
                    android:fromAlpha="1.0"
                    android:toAlpha="0.0" />
        <translate
            android:duration="1000"
            android:fromXDelta="0"
            android:fromYDelta="0"
            android:toXDelta="0"
            android:toYDelta="40%" />
    
    </set>

    3.从上面我们可以看出,这个LayoutAnimation的应用也是非常的简单。

    就是获得一个item想要的动画效果:AnimationUtils.loadAnimation( this, R.anim.history_clear_anim);

    然后以它作为参数,创建一个LayoutAnimation对象:new LayoutAnimationController

    然后就是在需要的地方添加一次动画:注意,只有执行它添加语句以后接下来的动画起一次作用

    4.如果我们想要在xml中实现的话,如下

    我们只要以上面的history_clear_anim.xml为一个动画属性创建一个xml文件就行了

    <layoutAnimation
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="0.5"
        android:animationOrder="normal"
        android:animation="@anim/history_clear_anim"
        />

    然后在我们的listview控件下使用

    <ListView>
    android:layoutAnimation="@animator/list_anim_layout" 
    </ListView>

     这里我们看一下

      android:animationOrder="normal"

    属性,它有三个值

    1.normal:加载的时候,动画从第一个加载项开始

    2.random:加载的时候,动画随机执行

    3.reverse:加载的时候,动画从最后一个开始执行

  • 相关阅读:
    fabric.js 学习
    前端基础回顾
    ubuntu16 mysql 远程连接
    Django rest_framework API 随笔
    django 学习笔记
    vue 返回上一页在原来的位置
    Django mysql 改用pymysql 驱动
    Material-UI
    设置placeholder的样式
    Cookie、session和localStorage、以及sessionStorage之间的区别
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_layoutAnimation_150320164.html
Copyright © 2011-2022 走看看