如何使用StateListAnimator? [英] How to use StateListAnimator?
问题描述
从文档:
新StateListAnimator类可以定义运行动画 当一个视图的状态发生改变。下面的例子演示了如何 定义StateListAnimator作为一个XML资源:
<! - 动画视图的translationZ属性时,pressed - > <选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目的android:STATE_ pressed =真正的>
<集>
< objectAnimator机器人:propertyName的=translationZ
机器人:时间=100
机器人:valueTo =2
机器人:值类型=floatType/>
<! - 你可以有其他的objectAnimator元素
这里的x和y,或其它性能 - >
< /集>
< /项目>
<项目安卓state_enabled =真
机器人:STATE_ pressed =假
机器人:state_focused =真正的>
<集>
< objectAnimator机器人:propertyName的=translationZ
机器人:时间=100
机器人:valueTo =2
机器人:值类型=floatType/>
< /集>
< /项目>
< /选择器>
然而,任何关于如何实际的使用的这个xml文件说。似乎有对资源都没法
类来获得一个 StateListAnimator
和 StateListAnimator
类不提供任何信息,无论是。
我们如何使用它?
在安卓→的一个新的XML属性已添加的查看的:
机器人:stateListAnimator:将基于状态的动画的视图。
此外实例化的 StateListAnimator 的对象编程的新方法:
loadStateListAnimator(上下文的背景下,INT ID)
已被添加到的 AnimatorInflater 的
这些上可以找到的的Android→的开发商preVIEW文件包。
From the docs:
The new StateListAnimator class lets you define animators that run when the state of a view changes. The following example shows how to define an StateListAnimator as an XML resource:
<!-- animate the translationZ property of a view when pressed --> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="2"
android:valueType="floatType"/>
<!-- you could have other objectAnimator elements
here for "x" and "y", or other properties -->
</set>
</item>
<item android:state_enabled="true"
android:state_pressed="false"
android:state_focused="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="100"
android:valueTo="2"
android:valueType="floatType"/>
</set>
</item>
</selector>
However, it says nothing about how to actually use this xml file. There seems to be no method on the Resources
class to get a StateListAnimator
, and the StateListAnimator
class does not provide any info either.
How can we use this?
In Android L a new xml attribute has been added for View :
android:stateListAnimator : Sets the state-based animator for the View.
Additionally for instantiating StateListAnimator object programmatically a new method :
loadStateListAnimator(Context context, int id)
has been added to AnimatorInflater .
These can be found on Android L developer preview documentation package.
这篇关于如何使用StateListAnimator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!