Android – How to make a scale animation around the view center

androidandroid-animationandroid-view

I load a scale animation from an XML file , then set it to view and start it .
I find that the animation is around the left top point of the view .
How can I make it around the center ?

This is my animation XML

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale 
        android:fromXScale="0.5"
        android:toXScale="1.1"
        android:fromYScale="0.5"
        android:toYScale="1.1"
        android:duration="200"/>
    <scale 
        android:fromXScale="1"
        android:toXScale="0.91"
        android:fromYScale="1"
        android:toYScale="0.91"
        android:startOffset="200"
        android:duration="400"/>
    <alpha 
        android:fromAlpha="0.5"
        android:toAlpha="1"
        android:duration="400"/>
    <alpha 
        android:fromAlpha="1"
        android:toAlpha="0"
        android:duration="300"
        android:startOffset="700"/>

</set>

And java code

rightAnim = AnimationUtils.loadAnimation(this, R.anim.show_fade_out);
rightAnimObj.setAnimation(rightAnim);
rightAnim.startNow();

Best Answer

Why not to use android:pivotX/android:pivotY ? http://developer.android.com/guide/topics/resources/animation-resource.html

The only thing - be careful with values, I think you'll need something like 50% or 50%p

Good luck