如何使用StateListAnimator? [英] How to use StateListAnimator?

查看:984
本文介绍了如何使用StateListAnimator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档

  

新StateListAnimator类可以定义运行动画   当一个视图的状态发生改变。下面的例子演示了如何   定义StateListAnimator作为一个XML资源:

 <! - 动画视图的translationZ属性时,pressed  - > <选择的xmlns:机器人=htt​​p://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

这些上可以找到的的Andr​​oid→的开发商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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆