Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale Animation behaving like translate animation

i am implementing scale animation for practice in a game.. i am following all guides but something weird is happening always instead of making the object larger. the animation not only makes the image larger but also moves it even though i am not using translate animation...

here the xml file

<?xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false"    
 xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="1.0"
    android:toXScale="1.4"
    android:fromYScale="1.0"
    android:toYScale="1.4"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fillAfter="false"
    android:duration="1000" />
 </set>

and here it is called in java

private void startAnimation(final ImageView imageView) {
        final Animation popAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.scalebounce);
        imageView.startAnimation(popAnim);
        popAnim.setAnimationListener(new AnimationListener() {

            public void onAnimationStart(Animation animation) {

            }

            public void onAnimationRepeat(Animation animation) {

            }

            public void onAnimationEnd(Animation animation) {
                imageView.clearAnimation();
                imageView.setVisibility(View.GONE);
            }
        });
    }

its really weird i have tried all the solutions i have found in the net but no luck it still does that translate behavior even though it is only scale... im making the image from small point then it becomes bigger(normal size). but i dont want it to move, just to be in its place. thanks :)

P.S i've been observing the animation and it seems that it takes larger space thats why it looks like it is moving..why does it takes larger space? not the actual image size?

like image 231
NoobMe Avatar asked Oct 09 '13 01:10

NoobMe


People also ask

What is a scale animation?

The Scale animation allows you to change a control's scale by increasing or decreasing the control through animation. Scale animation is applied to all the XAML elements in its parent control/panel. Scale animation doesn't affect the functionality of the control.

What is animation translate?

Animation is the process of making films in which drawings appear to move. ...


1 Answers

pivotX & pivotY need to be equal to around where your view should scale.

To demonstrate, here's a diagram to illustrate:

enter image description here

Your pivot point is currently outside the view, making it seem like your view is moving as well as scaling.

Set the pivotX / pivotY as 0 if you want the pivot point to be the top left corner of your view.

Set the pivotX = view.getWidth() / 2f & pivotY = view.getHeight() / 2f if you want the scale to be from the center (like the 1st image demonstrates)

Hope this helps :)

like image 138
Gil Moshayof Avatar answered Sep 28 '22 07:09

Gil Moshayof