我想制作一个动画可绘制的动画,在选中/未选中时动画。有"选择"有不同的动画。 - > "未选择"并且"没有被选中" - > "选择"我的问题是,当我选择我的视图时,它会触发正确的动画,但是当我取消选择时,它会反向触发相同的动画而不是正确的动画。有任何想法吗?
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- provide a different drawable for each state-->
<item
android:id="@+id/not_selected"
android:state_selected="false"
android:drawable="@drawable/vector_bars" />
<item
android:id="@+id/selected"
android:state_selected="true"
android:drawable="@drawable/vector_arrow" />
<!-- specify a transition -->
<transition
android:fromId="@id/selected"
android:toId="@id/not_selected"
android:drawable="@drawable/anim_arrow_to_bars"
android:reversible="false"/>
<transition
android:fromId="@id/not_selected"
android:toId="@id/selected"
android:drawable="@drawable/anim_bars_to_arrow"
android:reversible="false"/>
</animated-selector>
答案 0 :(得分:1)
好的,经过更广泛的搜索,我找到了答案。我添加了2个额外状态并稍微改变了转换,它现在按预期工作。
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- provide a different drawable for each state-->
<item
android:id="@+id/not_selected_pressed"
android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/vector_bars" />
<item
android:id="@+id/selected_pressed"
android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/vector_arrow" />
<item
android:id="@+id/not_selected"
android:state_selected="false"
android:drawable="@drawable/vector_bars" />
<item
android:id="@+id/selected"
android:state_selected="true"
android:drawable="@drawable/vector_arrow" />
<!-- specify a transition -->
<transition
android:fromId="@id/selected_pressed"
android:toId="@id/not_selected"
android:drawable="@drawable/anim_arrow_to_bars"
android:reversible="false"/>
<transition
android:fromId="@id/selected_pressed"
android:toId="@id/selected"
android:drawable="@drawable/anim_bars_to_arrow"
android:reversible="false"/>
</animated-selector>