Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android scale image view with animation

i have an ImageView and would like to scale it smaller with animation. i use

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <scale
        android:fromXScale="1.0"
        android:toXScale="0.7"
        android:fromYScale="1.0"
        android:toYScale="0.7"
        android:pivotX="50%"
        android:pivotY="10%"
        android:duration="1500" />
</set>

This works good. But after the animation is finished the image gets back to its original size. Any ideas why?

like image 566
Ghost108 Avatar asked Nov 25 '15 12:11

Ghost108


1 Answers

Try with this code, it will not reset the image size after animation, here view is the imageview you want to animate.

ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 0.5f);
ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 0.5f);
scaleDownX.setDuration(1000);
scaleDownY.setDuration(1000);

AnimatorSet scaleDown = new AnimatorSet();
scaleDown.play(scaleDownX).with(scaleDownY);

scaleDown.start();
like image 139
Nigam Patro Avatar answered Sep 22 '22 22:09

Nigam Patro