我有以下动画选择器:
<!-- res/drawable/animated_state.xml -->
<animated-selector
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- provide a different drawable for each state-->
<item
android:id="@+id/pressed"
android:drawable="@drawable/button_pressed"
android:state_pressed="true"/>
<item
android:id="@+id/none"
android:state_pressed="false"
android:drawable="@drawable/button_not_pressed"/>
<!-- specify a transition -->
<transition
android:fromId="@+id/none"
android:toId="@+id/pressed">
<animation-list>
<item
android:duration="100"
android:drawable="@drawable/button_pressing1"/>
<item
android:duration="100"
android:drawable="@drawable/button_pressing2"/>
<item
android:duration="100"
android:drawable="@drawable/button_pressing3"/>
</animation-list>
</transition>
<!-- specify a transition -->
<transition
android:fromId="@+id/pressed"
android:toId="@+id/none">
<animation-list>
<item
android:duration="100"
android:drawable="@drawable/button_pressing2"/>
</animation-list>
</transition>
</animated-selector>
设置为视图的背景:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="30dp"
android:clickable="true"
android:background="@drawable/animated_state"
android:layout_centerInParent="true"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@android:color/darker_gray"
android:duplicateParentState="true"
android:text="Press\n&\nWatch"
android:gravity="center"
tools:text="Text"
tools:textColor="#000"
/>
</LinearLayout>
</RelativeLayout>
当我按下视图时,我看到的是转换按预期开始 button_not_pressed - &gt; button_pressing1 - &gt; button_pressing2 - &gt;执行了button_pressing3 ,但我希望最后的转换是 button_pressed ,这不会发生。
当我删除android:drawable="@drawable/button_pressed"
行时,我收到错误,状态必须有一个drawable ,我想这意味着它应该有一个函数...
状态中定义的drawable是最终的吗?或者我是否必须将动画列表中的最后一项设置为最终状态?或者我做错了什么?