Scale Animation not smooth in android on image view

3.9k views Asked by At

I have use Scale Animation for zooming an image in my app. It's working fine zoom image level proper which we want but my issue is when zooming the image not zoom smoother. image size is 1.4 mb.

ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 2.5f,
                        1f, 2.5f, Animation.RELATIVE_TO_PARENT,
                        1.05f, Animation.RELATIVE_TO_PARENT, 1.05f);
  scaleAnimation.setFillAfter(true);
  scaleAnimation.setDuration(400);
  img.startAnimation(scaleAnimation);
3

There are 3 answers

0
Sohail Zahid On

Android animations with Zoom animation smoothly Here.

You can custom them for making more smooth.

0
Akshay Bhat 'AB' On

If your min sdk version is greater than 13 then you can try

img.animate().scaleX(2.5f).scaleY(2.5f).setDuration(400).start();
0
Harshad Pansuriya On

Create 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:pivotX="50%"
           android:pivotY="50%"
           android:duration="400"/>
</set>

and Use this way..

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

It will give you smooth Animation.

Note : make sure that to get smooth animation you have to set android:pivotX and android:pivoty to half of screen.