Mahalakshmi Saravanan
Mahalakshmi Saravanan

Reputation: 295

ImageView to zoom out and scale the image animation in android

I want image to zoom out and scale as Twitter Splash screen animation but I am not able to first zoom out the image and scale. Here's is my code

imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            imageView.animate()
                    .setStartDelay(500)
                    .setDuration(1000)
                    .scaleX(20)
                    .scaleY(20)
                    .alpha(0);
        }
    });

Upvotes: 0

Views: 1188

Answers (2)

Sunil Sunny
Sunil Sunny

Reputation: 3994

You can do almost any animations with ObjectAnimator and it's very smooth.

Here is a sample code. In this case image will scale up from 1x to 2x, You can adjust the values as your need.Now if you want to scale down then change 2x to 0.5x which will scale down image to 50% of original image.

    ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(imageView, "scaleX", 1.0f, 2.0f);
    scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleXAnimation.setDuration(1500);
    ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(imageView, "scaleY", 1.0f, 2.0f);
    scaleYAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleYAnimation.setDuration(1500);
    ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(imageView, "alpha", 1.0F, 0F);
    alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    alphaAnimation.setDuration(1500);


    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(scaleXAnimation).with(scaleYAnimation).with(alphaAnimation);
    animatorSet.setStartDelay(500);
    animatorSet.start();

Upvotes: 1

Harsh Patel
Harsh Patel

Reputation: 1086

You didn't mention scale from variable

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
    <scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5" >
    </scale>
 </set>

Upvotes: 2

Related Questions