安卓动画知识总结 Animation AnimationSet LayoutAnimation

本文总结了Android动画中AnimationSet的关键特性,包括如何影响子动画的属性如duration、repeatMode、fillBefore和fillAfter。同时提到了被忽略的属性如repeatCount和fillEnabled,并解释了startOffset和shareInterpolator对AnimationSet本身的适用性。
摘要由CSDN通过智能技术生成
本文由PurpleSword(jzj1993)原创,转载请注明
原文网址 http://blog.csdn.net/jzj1993

常见动画有几种
控件View的动画(如Dialog窗口中的圆形进度条)
空间Window的动画(如DialogWindow,PopupWindow的动画,Activity切换时整个Window页面的动画)
ViewGroup的LayoutAnimation动画,每个子控件按照设定的顺序、延迟播放动画

动画常用anim/*.xml定义

xml中定义动画,可直接使用<translate><scale><alpha><rotate>标签直接定义,也可以放在<set>标签中,里面定义的动画将同时开始播放。
两者都可使用AnimationUtils.loadAnimation方法加载。如果是set标签定义,加载时返回的是AnimationSet实例(AnimationSet继承自Animation)
在set标签中设置的一些属性,会直接覆盖它里面定义动画的对应属性,而 AnimationSet的另外一些从Animation继承的属性则无效,下面是AnimationSet类的官方说明。

Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore), the values of AnimationSet override the child values.

The way that AnimationSet inherits behavior from Animation is important to understand. Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:

    • duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object, will be pushed down to all child animations.
    • repeatCount, fillEnabled: These properties are ignored for AnimationSet.
    • startOffset, shareInterpolator: These properties apply to the AnimationSet itself.
Starting with android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH, the behavior of these properties is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored for AnimationSet). That is, calling setDuration(500) on an AnimationSet has the same effect as declaring android:duration="500" in an XML resource for an AnimationSet object.


常规补间动画:弹跳(移动)

Layout/activity_welcome_anim.xml
(0%p表示占父组件尺寸的百分比)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="500"
        android:fromXDelta="0"
        android:fromYDelta="0%p"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toXDelta="0"
        android:toYDelta="42%p" />
    <translate
        android:duration="350"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:startOffset="500"
        android:toXDelta="0"
        android:toYDelta="-21%p" />
    <translate
        android:duration="350"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="850"
        android:toXDelta="0"
        android:toYDelta="21%p" />
    <translate
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值