Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android image scale animation relative to center point

I have an ImageView and I do a simple scale animation to it. Very standard code.

My scale_up.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">     <scale android:fromXScale="1"            android:fromYScale="1"            android:toXScale="1.2"            android:toYScale="1.2"            android:duration="175"/> </set> 

My animation code:

Animation a = AnimationUtils.loadAnimation(this, R.anim.scale_up); ((ImageView) findViewById(R.id.circle_image)).startAnimation(a); 

The problem:

When the image scales it doesn't scale from the center, but from the top left corner. In other words, the scaled version of the image doesn't have the same point as the center, but it has the same top-left point. Here's an image that explains what I mean:

How the animation scales How I want it

The first image is how the animation scales and the second image is how I want it to scale. It should keep the center point the same. I have tried setting up gravity on the image, on the container, aligning left or right, it always scales the same.

I'm using RelativeLayout for the main screen and ImageView is located into another RelativeLayout, but I tried other layouts, no change.

like image 463
Tomislav Markovski Avatar asked Dec 07 '11 01:12

Tomislav Markovski


1 Answers

50% is center of animated view.

50%p is center of parent

<scale     android:fromXScale="1.0"     android:toXScale="1.2"     android:fromYScale="1.0"     android:toYScale="1.2"     android:pivotX="50%"     android:pivotY="50%"     android:duration="175"/> 
like image 118
Jiang Qi Avatar answered Sep 27 '22 19:09

Jiang Qi