9

I'd like to grow a view with each click using a ScaleAnimation. I've managed the effects of the animation persist after it has finished with the fillAfter, but the problem now is, the animation always starts from state 0 (as the View is defined in the XML) - on click the view resets and animates back to the state it was just after the first animation.

The animation is defined in an XML:

<scale 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
  android:fromXScale="1" 
  android:toXScale="1.5" 
  android:fromYScale="1" 
  android:toYScale="1.5" 
  android:pivotX="50%" 
  android:pivotY="50%" 
  android:duration="1000" 
  android:fillAfter="true" 
/>
Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
Anze
  • 491
  • 1
  • 4
  • 9

2 Answers2

26

I solved the issue by not resorting to animation defined in the XML, but rather doing

anim = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

and adjusting from/to each time I needed to expand it. I'm not so sure that's a good thing regarding performance, but it works nicely.

Hameno
  • 351
  • 3
  • 14
Anze
  • 491
  • 1
  • 4
  • 9
1

How exactly is the animation defined?

When defining ScaleAnimation with Java code, you can set fromX/fromY (look here) starting scaling factors, so I assume you can do the same with XML attributes.

Dimitar Dimitrov
  • 16,032
  • 5
  • 53
  • 55