shaonAshraf
shaonAshraf

Reputation: 1107

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?

Upvotes: 3

Views: 2634

Answers (2)

shaonAshraf
shaonAshraf

Reputation: 1107

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

Upvotes: 1

XGouchet
XGouchet

Reputation: 10203

You should also add a android:fillBefore="true" in your animation.

The in the forward animation your view usually will have a scale of 1 which mean you don't need to set it at start. But in the reverse animation you start at default (ie 1) and animate to... 1

Upvotes: 1

Related Questions