I would like to add a complete example of the animation of the progress icon in ImageView, it is based on Mark Hetherington's answer.
So my animation looks like this:
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="-360" android:duration="100" android:drawable="@drawable/ic_loop_black_24dp" />
icon comes from https://material.io/icons/
then my layout contains an ImageView as follows:
<ImageView android:id="@+id/progress" android:layout_marginTop="0dp" android:layout_marginLeft="-3dp" android:layout_width="30dp" android:layout_height="30dp" android:visibility="gone" android:scaleType="fitCenter" android:background="@drawable/progress_anim" android:layout_gravity="center_horizontal|center_vertical" />
and finally in the code, when I need to show the animation:
RotateDrawable rotateDrawable = ((RotateDrawable)progressImage.getBackground()); ObjectAnimator anim = ObjectAnimator.ofInt(rotateDrawable, "level", 0, 10000); anim.setDuration(1000); anim.setRepeatCount(ValueAnimator.INFINITE); anim.start();
marcinj Jun 15 '17 at 20:26 2017-06-15 20:26
source share