从文档:
新的 StateListAnimator 类允许您定义在视图状态更改时运行的动画器。以下示例显示如何将 StateListAnimator 定义为 XML 资源:
<!-- 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>
但是,它没有说明如何实际使用这个 xml 文件。该类似乎没有Resources
获取 a 的方法StateListAnimator
,并且StateListAnimator
该类也不提供任何信息。
我们如何使用它?