Animate zoom in via center of an image in Android with xml
I am trying to do some simple image zooming and panning with Android and I have two simple questions.
First, when I call the animation using scale
, it zooms using the upper left-hand corner of the image as the origin but I would like it to zoom from the center of the image.
Here is the xml I have for the scale:
<scale android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
开发者_如何学编程 android:detachWallpaper="true"
android:duration="3000"></scale>
and in my code:
a = AnimationUtils.loadAnimation(this, R.anim.set);
a.reset();
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.clearAnimation();
iv.startAnimation(a);
For scaling a image from center you have to set the pivotX and pivotY
try this code for scaling from center and retaining the state after scaling,
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="5"
android:fromYScale="1"
android:toYScale="5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>
Thanks...
精彩评论