属性动画-xml各个字段解释

Property Animation


An animation defined in XML that modifies properties of the target object, such as background color or alpha value, over a set amount of time.

FILE LOCATION:
res/animator/filename.xml
The filename will be used as the resource ID.
COMPILED RESOURCE DATATYPE:
Resource pointer to a  ValueAnimatorObjectAnimator, or  AnimatorSet.
RESOURCE REFERENCE:
In Java:  R.animator.filename
In XML:  @[package:]animator/filename
SYNTAX:
<set
  android:ordering=["together" | "sequentially"]>

    <objectAnimator
        android:propertyName="string"
        android:duration="int"
        android:valueFrom="float | int | color"
        android:valueTo="float | int | color"
        android:startOffset="int"
        android:repeatCount="int"
        android:repeatMode=["repeat" | "reverse"]
        android:valueType=["intType" | "floatType"]/>

    <animator
        android:duration="int"
        android:valueFrom="float | int | color"
        android:valueTo="float | int | color"
        android:startOffset="int"
        android:repeatCount="int"
        android:repeatMode=["repeat" | "reverse"]
        android:valueType=["intType" | "floatType"]/>

    <set>
        ...
    </set>
</set>

The file must have a single root element: either <set><objectAnimator>, or <valueAnimator>. You can group animation elements together inside the <set> element, including other <set> elements.

ELEMENTS:
<set>
A container that holds other animation elements ( <objectAnimator><valueAnimator>, or other  <set> elements). Represents an  AnimatorSet.

You can specify nested <set> tags to further group animations together. Each <set> can define its own ordering attribute.

attributes:

android:ordering
Keyword. Specifies the play ordering of animations in this set.
Value Description
sequentially Play animations in this set sequentially
together (default) Play animations in this set at the same time.
<objectAnimator>
Animates a specific property of an object over a specific amount of time. Represents an ObjectAnimator.

attributes:

android:propertyName
StringRequired. The object's property to animate, referenced by its name. For example you can specify  "alpha" or  "backgroundColor" for a View object. The  objectAnimatorelement does not expose a  target attribute, however, so you cannot set the object to animate in the XML declaration. You have to inflate your animation XML resource by calling loadAnimator() and call  setTarget() to set the target object that contains this property.
android:valueTo
float, int, or colorRequired. The value where the animated property ends. Colors are represented as six digit hexadecimal numbers (for example, #333333).
android:valueFrom
float, int, or color. The value where the animated property starts. If not specified, the animation starts at the value obtained by the property's get method. Colors are represented as six digit hexadecimal numbers (for example, #333333).
android:duration
int. The time in milliseconds of the animation. 300 milliseconds is the default.
android:startOffset
int. The amount of milliseconds the animation delays after  start() is called.
android:repeatCount
int. How many times to repeat an animation. Set to  "-1" to infinitely repeat or to a positive integer. For example, a value of  "1" means that the animation is repeated once after the initial run of the animation, so the animation plays a total of two times. The default value is "0", which means no repetition.
android:repeatMode
int. How an animation behaves when it reaches the end of the animation. android:repeatCount must be set to a positive integer or  "-1" for this attribute to have an effect. Set to  "reverse" to have the animation reverse direction with each iteration or "repeat" to have the animation loop from the beginning each time.
android:valueType
Keyword. Do not specify this attribute if the value is a color. The animation framework automatically handles color values
Value Description
intType Specifies that the animated values are integers
floatType (default) Specifies that the animated values are floats
<animator>
Performs an animation over a specified amount of time. Represents a  ValueAnimator.

attributes:

android:valueTo
float, int, or colorRequired. The value where the animation ends. Colors are represented as six digit hexadecimal numbers (for example, #333333).
android:valueFrom
float, int, or colorRequired. The value where the animation starts. Colors are represented as six digit hexadecimal numbers (for example, #333333).
android:duration
int. The time in milliseconds of the animation. 300ms is the default.
android:startOffset
int. The amount of milliseconds the animation delays after  start() is called.
android:repeatCount
int. How many times to repeat an animation. Set to  "-1" to infinitely repeat or to a positive integer. For example, a value of  "1" means that the animation is repeated once after the initial run of the animation, so the animation plays a total of two times. The default value is "0", which means no repetition.
android:repeatMode
int. How an animation behaves when it reaches the end of the animation. android:repeatCount must be set to a positive integer or  "-1" for this attribute to have an effect. Set to  "reverse" to have the animation reverse direction with each iteration or "repeat" to have the animation loop from the beginning each time.
android:valueType
Keyword. Do not specify this attribute if the value is a color. The animation framework automatically handles color values.
Value Description
intType Specifies that the animated values are integers
floatType (default) Specifies that the animated values are floats
EXAMPLE:
XML file saved at  res/animator/property_animator.xml:

<set android:ordering="sequentially">
    <set>
        <objectAnimator
            android:propertyName="x"
            android:duration="500"
            android:valueTo="400"
            android:valueType="intType"/>
        <objectAnimator
            android:propertyName="y"
            android:duration="500"
            android:valueTo="300"
            android:valueType="intType"/>
    </set>
    <objectAnimator
        android:propertyName="alpha"
        android:duration="500"
        android:valueTo="1f"/>
</set>

In order to run this animation, you must inflate the XML resources in your code to an AnimatorSetobject, and then set the target objects for all of the animations before starting the animation set. CallingsetTarget() sets a single target object for all children of the AnimatorSet as a convenience. The following code shows how to do this:

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
    R.anim.property_animator);
set.setTarget(myObject);
set.start();
SEE ALSO:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值