Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 374
shaonAshraf Avatar asked Apr 29 '26 23:04

shaonAshraf


1 Answers

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

like image 58
XGouchet Avatar answered May 01 '26 12:05

XGouchet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!