How to use StateListAnimator?

In docs :

The new StateListAnimator class allows you to define animators that run when the view state changes. The following example shows how to define 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 use this XML file. There is apparently no method in the Resources class to get the StateListAnimator , and the StateListAnimator class also does not provide any information.

How can we use this?

+14
android android-5.0-lollipop
Jun 27 '14 at 18:27
source share
1 answer

In Android L, a new xml attribute has been added for viewing:

 android:stateListAnimator : Sets the state-based animator for the View. 

Additionally, to create a StateListAnimator object programmatically, a new method:

 loadStateListAnimator(Context context, int id) 

was added to AnimatorInflater.

They can be found in the Android L Developer Preview Kit.

+14
Jun 27 '14 at 19:03
source share



All Articles