Search code examples
androidxmlscaleandroid-animation

Android: scale animation does not work when direction is changed


In my Android app, I hava a scale animation.

<set xmlns:android="http://schemas.android.com/apk/res/android"   android:interpolator="@android:anim/accelerate_interpolator"   android:fillEnabled="true"  android:fillAfter="true"  >
 <scale android:fromXScale="1.0" android:toXScale="0.0"   android:fromYScale="1.0"    android:toYScale="1.0"      android:duration="32000"   />
 </set>

it works fine. it scales the view from left to right. but I need to scale from right to left. so when I modify the fromXScale="-1.0", the animation does not happen and the view is scaled instantly without animation. My animation xml for the reverse direction is given below:

 <set xmlns:android="http://schemas.android.com/apk/res/android"   android:interpolator="@android:anim/accelerate_interpolator"   android:fillEnabled="true"  android:fillAfter="true"  >            
  <scale android:fromXScale="-1.0" android:toXScale="0.0"   android:fromYScale="1.0"    android:toYScale="1.0"      android:duration="32000"   /> 
 </set>

How can I animate the View from reverse direction? what is wrong with my code?


Solution

  • using Pivot solved the problem. Its a better practice to control direction of an animation through pivotX and pivotY.