Issue with <scale> animations in Android

When you are writing ViewAnimators, for the ‘<scale>’ type, make sure to provide both ‘from’ and ‘to’ for XScale’ and ‘YScale’ even if there is no changes in scale of one of X or Y.

Not providing one of it will vanish the view.

Below is the example of XML file for an scale animator which works.

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="0.1"
android:fromYScale="1.0"
android:toYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="4000">
</scale>

Below snippet doesn’t work.

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="0.1"
android:pivotX="0%"
android:pivotY="0%"
android:duration="4000">
</scale>

For the above animation to work, one need something like below.

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="0.1"
android:fromYScale="1.0"
android:toYScale="1.0"
android:pivotX="0%"
android:pivotY="0%"
android:duration="4000">
</scale>

Notice that the fromYScale and toYScale are same above.

More about animations here

Like what you read? Give Amar Tumballi a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.