views:

28

answers:

1

So I used a ScaleAnimation to make a timebar shrink in a game. When the current level was finished, I wanted the timebar to quickly shrink to the bottom. So what I did was that if 30% of the time had passed, I assumed that 30% of the timebar was gone. So I just started a new ScaleAnimation that started at 70% of the timebars original size, assuming that this would look like a single smooth animation that speed up when the level was finished. Unfortunately the scaleanimation does not move evenly. It moves slower at the start and end, and faster in the middle.

So now I have three choices: Either I figure out how to make the ScaleAnimation move in an even speed, or I figure out the formula of how fast it moves, so I can determine exactly how big it is when a certain percent of the animation has played. Or, I find a smarter way altogether to do this timebar. Suggestions? :)

Cheers,

+1  A: 

The method android uses to create the tween animation is decided by which interpolator you use. From the android website:

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance, AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

The choices are (from android website again):

AccelerateDecelerateInterpolator, AccelerateInterpolator, AnticipateInterpolator, AnticipateOvershootInterpolator, BounceInterpolator, CycleInterpolator, DecelerateInterpolator, LinearInterpolator, OvershootInterpolator

So from what you describe you probably want to choose the LinearInterpolator which would look something like the following:

   <scale
          android:interpolator="@android:anim/linear_interpolator"
          android:fromXScale="1.0"
          android:toXScale="1.4"
          android:fromYScale="1.0"
          android:toYScale="0.6"
          android:pivotX="50%"
          android:pivotY="50%"
          android:fillAfter="false"
          android:duration="700" />

Experiment with different interpolators to see which you think best suits your needs.

stealthcopter