Hi There! 
I want to use check box with animated background to switch between checked 
and unchecked states using only android resources without any java code (I 
want to have separate resources for older and newer android versions)
I found out some guide here 
<https://developer.android.com/training/material/animations.html> but it 
does't work as I want. So I should have two transition for each state from 
state_on to state_off and from state_off to state_on.
I've tried to write animated-selector as in guide but it does't animate 
states switch at all.
This is my code of selector:
<animated-selector
 xmlns:android="http://schemas.android.com/apk/res/android";>
 <!-- provide a different drawable for each state-->
 <item
 android:id="@+id/state_on"
 android:drawable="@drawable/rec_on"
 android:state_checked="true"/>

 <item
 android:id="@+id/state_off"
 android:drawable="@drawable/rec_off"/>

 <transition
 android:drawable="@drawable/rec_off"
 android:fromId="@+id/state_off"
 android:toId="@+id/state_on">
 <animation-list>
 <item
 android:drawable="@drawable/out_on"
 android:duration="500"/>
 </animation-list>
 </transition>


 <transition
 android:drawable="@drawable/rec_on"
 android:fromId="@+id/state_on"
 android:toId="@+id/state_off">
 <animation-list>
 <item
 android:drawable="@drawable/out_off"
 android:duration="500"/>
 </animation-list>
 </transition>

</animated-selector>


@drawable/out_on code:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android";
 android:drawable="@drawable/rec_off">
 <target
 android:name="outer"
 android:animation="@anim/outer_on"/>
 <target
 android:name="inner"
 android:animation="@anim/inner_on"/>
</animated-vector>

all animations has almost the same code but it depends of state.
@anim/inner_on code:
<?xml version="1.0" encoding="utf-8"?>
<set>
 <objectAnimator
 xmlns:android="http://schemas.android.com/apk/res/android";
 android:duration="500"
 android:propertyName="pathData"
 android:valueFrom="M 70 992.3622 C 75.5228474983 992.3622 80 996.839352502 
80 1002.3622 C 80 1007.8850475 75.5228474983 1012.3622 70 1012.3622 C 
64.4771525017 1012.3622 60 1007.8850475 60 1002.3622 C 60 996.839352502 
64.4771525017 992.3622 70 992.3622 Z"
 android:valueTo="M 70 957.3622 C 94.8528137424 957.3622 115 977.509386258 
115 1002.3622 C 115 1027.21501374 94.8528137424 1047.3622 70 1047.3622 C 
45.1471862576 1047.3622 25 1027.21501374 25 1002.3622 C 25 977.509386258 
45.1471862576 957.3622 70 957.3622 Z"
 android:valueType="pathType"/>
</set>


And then I tried next solution with single transition but with 
reversible=true:

<animated-selector
 xmlns:android="http://schemas.android.com/apk/res/android";>
 <!-- provide a different drawable for each state-->
 <item android:id="@+id/state_on"
 android:drawable="@drawable/rec_on"
 android:state_checked="true"/>

 <item android:id="@+id/state_off"
 android:drawable="@drawable/rec_off"/>

 <!-- specify transitions -->
 <transition
 android:fromId="@+id/state_off"
 android:reversible="true"
 android:toId="@+id/state_on">
 <animated-vector android:drawable="@drawable/rec_off">
 <target
 android:name="outer"
 android:animation="@animator/outer_on" />
 <target
 android:name="inner"
 android:animation="@animator/inner_on" />
 </animated-vector>
 </transition>

</animated-selector>


This selector animates states switch but in a quite strange way: if my 
checkbox has standard button drawable - it works perfectly, but if I set 
another drawable for button or @null selector skips transition from 
state_on to state_of.

Also I've tried to move transitions into <item> tag and I've got the same 
result as with first animated-selector.

Moreover I found out that <set> tag is't allowed inside <item> tag as in 
template.

Full source code you can find here 
<https://github.com/alexandersokol/vector-animation-drawable>. It has two 
branches - master and google_example

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/4dcafda1-09e8-4697-89e5-6d66fec41804%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to