动画系列——LayoutAnimation与GridLayoutAnimation

LayoutAnimation与GridLayoutAnimation

LayoutAnimation

​ 对viewGroup及其子类添加进入统一动画的LayoutAnimation和针对grideView添加进入动画的gridLayoutAnimation

使用示例

​ layoutAnimation属性只在ViewGroup及其子类创建时有效

<!-- anim/ayout_animation.xml -->
<!-- xml形式实现 -->
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
                 android:delay="1"
                 android:animationOrder="normal"
                 android:animation="@anim/slide_in_left"/>
<!-- java形式实现 -->
Animation animation= AnimationUtils.loadAnimation(this,R.anim.slide_in_left);   
LayoutAnimationController controller = new LayoutAnimationController(animation);   
controller.setOrder(LayoutAnimationController.ORDER_REVERSE);   
controller.setDelay(0.3f);  
mListView.setLayoutAnimation(controller);
mListView.startLayoutAnimation();

<!-- anim/slide_in_left.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 			android:duration="1000">
    <translate android:fromXDelta="-50%p" android:toXDelta="0"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"/>
</set>
<!-- 使用 -->
<ListView
          android:id="@+id/listview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layoutAnimation="@anim/layout_animation"/>

属性解析

属性解析
delay每个item延时时间的百分比,默认0.5,即在上一个item动画开始后的0.5倍时间后开始动画
animationOrder动画顺序,normal:正序,reverse:倒序,random:随机
animation指定每个item的入场动画,只能使用animation动画

GridLayoutAnimation

使用示例

<!-- xml实现 -->
<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
                     android:rowDelay="75%"
                     android:columnDelay="60%"
                     android:directionPriority="none"
                     android:direction="bottom_to_top|right_to_left"
                     android:animation="@android:anim/slide_in_left"/>
<!-- java实现 -->
Animation animation = AnimationUtils.loadAnimation(MyActivity.this,R.anim.slide_in_left);
GridLayoutAnimationController controller = new GridLayoutAnimationController(animation);
controller.setColumnDelay(0.75f);
controller.setRowDelay(0.5f);        controller.setDirection(GridLayoutAnimationController.DIRECTION_BOTTOM_TO_TOP|GridLayoutAnimationController.DIRECTION_LEFT_TO_RIGHT);
controller.setDirectionPriority(GridLayoutAnimationController.PRIORITY_NONE);
gridView.setLayoutAnimation(controller);
gridView.tartLayoutAnimation();

属性解析

属性解析
rowDelay每一行动画开始的延迟
columnDelay每一列动画开始的延迟
directionPriority方向优先级,row:行优先,collumn:列优先,none:同时进行。如,行优先,则一行一行的执行动画,第一行执行完后再执行第二行,其他同理
direction动画方向,默认left_to_right。left_to_right,right_to_left,top_to_bottom,bottom_to_top,四个值可以使用"|"连接
animation指定每个item的入场动画,只能使用animation动画

自定义LayoutAnimation

​ 自定义类继承LayoutAnimationController或GridLayoutAnimationController

public class MyGridLayoutAnimationController extends GridLayoutAnimationController {
    public MyGridLayoutAnimationController(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyGridLayoutAnimationController(Animation animation) {
        super(animation);
    }

    public MyGridLayoutAnimationController(Animation animation, float columnDelay, float rowDelay) {
        super(animation, columnDelay, rowDelay);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值