简体   繁体   中英

Scale Animation not smooth in android on image view

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);

如果您的min sdk版本大于13,那么您可以尝试

img.animate().scaleX(2.5f).scaleY(2.5f).setDuration(400).start();

Android animations with Zoom animation smoothly Here.

You can custom them for making more smooth.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM