44

I have an image drawable. i rotating the image like a progress bar.

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="360" android:drawable="@drawable/spinner_white_48" />

i want to increase the rotation speed? for that, What attribute i have to use?

Praveen
  • 90,477
  • 74
  • 177
  • 219

6 Answers6

138

Setting duration and/or repeat count did not help me with an indeterminate ProgressBar animation. I had to increase the toDegrees to have it make additional loops:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_indeterminate_progress"
    android:duration="1"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="1080" /> <!--1080 is 3 loops instead of 1 in same amt of time-->
DustinB
  • 11,037
  • 5
  • 46
  • 54
  • 1
    It become skips many degrees at animation repeat when we set it to a value like 0 to non-integer multiple of 360 (e.g. 540) degrees. is there a workaound for this – Buddy Sep 03 '15 at 01:50
  • Great solution, only this one helped with indeterminate progress. – Taras Lozovyi Dec 04 '19 at 11:36
46

According to this link:

The rotation speed of the indeterminate progress bar is fixed at one revolution every 4 seconds, changing the duration attribute in the drawable XML has no effect. If you prefer to speed it up, you can change the toDegrees attribute to multiples of 360:

  • 720 makes one turn in 2 seconds
  • 1080 makes one turn in 1.33 seconds
  • 1440 makes one turn in 1 second

In addition, you can just use indeterminateDuration for the ProgressBar.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
14

add in code to progress.xml

 <rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0"
    android:toDegrees="1080" /> <!--1080 is 3 loops instead of 1 in same amt of time-->
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
Mr_Moradi
  • 354
  • 5
  • 9
5

Set the duration and repeatCount that you want the animation to run.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • 2
    What if the repeatCount should be 0, so that it rotates forever (used for progressBar, in "indeterminateDrawable") ? The duration doesn't seem to do anything in this case... – android developer May 10 '16 at 07:51
3
android:duration="required value in ms"
Primal Pappachan
  • 25,857
  • 22
  • 67
  • 84
1

add in code to progress.xml

<?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="1440">
    
        <shape
            android:shape="ring"
            android:innerRadiusRatio="3"
            android:thicknessRatio="8"
            android:useLevel="false">
    
            <size
                android:width="76dip"
                android:height="76dip" />
    
            <gradient
                android:type="sweep"
                android:useLevel="false"
                android:startColor="#FF0000"
                android:endColor="#00ffffff"
                android:angle="0"/>
    
        </shape>
    
    </rotate>