Reputation: 25
I am trying to scale a vector drawable with the help of ObjectAnimator
based on state of button is selected or not. I a trying to do this as,
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_map_colored"
android:state_selected="true" >
<set>
<objectAnimator
android:duration="150"
android:propertyName="scaleX"
android:valueTo="2"
android:valueType="floatType" />
<objectAnimator
android:duration="5000"
android:propertyName="scaleY"
android:valueTo="2"
android:valueType="floatType"/>
</set>
</item>
<item android:drawable="@drawable/ic_map" android:state_selected="false" >
<set>
<objectAnimator
android:duration="150"
android:propertyName="scaleX"
android:valueTo="1"
android:valueType="floatType"/>
<objectAnimator
android:duration="5000"
android:propertyName="scaleY"
android:valueTo="1"
android:valueType="floatType"/>
</set>
</item>
</selector>
Simply I am trying to increase scale on select of image and to decrease scale on deselect imageview. But above code is not working, how to do it?
Upvotes: 1
Views: 570
Reputation:
Try this code ..
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<set>
<objectAnimator
android:duration="150"
android:propertyName="scaleX"
android:valueTo="2"
android:valueType="floatType" />
<objectAnimator
android:duration="5000"
android:propertyName="scaleY"
android:valueTo="2"
android:valueType="floatType"/>
</set>
<set>
<objectAnimator
android:duration="150"
android:propertyName="scaleX"
android:valueTo="1"
android:valueType="floatType"/>
<objectAnimator
android:duration="5000"
android:propertyName="scaleY"
android:valueTo="1"
android:valueType="floatType"/>
</set>
</set>
then call like below code..
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(getActivity(), R.animator.sample);
set.setTarget(fab); // set the view you want to animate
set.start();
Upvotes: 2