Android custom circular ProgressBar direction
Asked Answered
A

5

9

I have a custom Circular Progressbar. This is the drawable I have for it to be determinate:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/secondaryProgress">
    <shape
        android:innerRadiusRatio="6"
        android:shape="ring"
        android:thicknessRatio="20.0"
        android:useLevel="true">
     <gradient
          android:centerColor="#999999"
          android:endColor="#999999"
          android:startColor="#999999"
          android:type="sweep" />
    </shape>
  </item>
  <item android:id="@android:id/progress">
   <rotate
      android:fromDegrees="270"
      android:pivotX="50%"
      android:pivotY="50%"
      android:toDegrees="270">

  <shape
      android:innerRadiusRatio="6"
      android:shape="ring"
      android:thicknessRatio="20.0"
      android:useLevel="true">


    <rotate
        android:fromDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="0" />

    <gradient
        android:centerColor="?attr/colorAccent"
        android:endColor="?attr/colorAccent"
        android:startColor="?attr/colorAccent"
        android:type="sweep" />

      </shape>
    </rotate>
  </item>
</layer-list>

I want it to show the progress in a clockwise direction, but now it's showing counterclockwise.

How do I change it?

Allina answered 3/7, 2017 at 11:23 Comment(1)
how are you incrementing progress? I have a circular progress bar, used your drawable, and it rotates clockwiseBriquette
A
20

I guess you're using an rtl language? You can force the progress bar to an ltr or clockwise direction by setting the layoutDirection property on your ProgressBar.

<ProgressBar
    ...
    android:layoutDirection="ltr" />
Amalberga answered 5/7, 2017 at 21:7 Comment(0)
K
2

By using latest versions of material design library, you can achieve this:

  • in the layout with this attribute
    app:indicatorDirectionCircular
    
  • or programmatically with this method
    setIndicatorDirection()
    

Refer here for more info.

Karajan answered 8/1, 2021 at 10:2 Comment(0)
D
0

Change this

<rotate
    android:fromDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="0" />

to

<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" />
Doom answered 3/7, 2017 at 11:42 Comment(1)
Doesn't work. It was that way at the beginning, and I tried changing it.Allina
T
0

I'm not sure if it will work, but just try to set android:toDegrees="-360" like this :

<rotate
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="-360" />
Tippler answered 5/7, 2017 at 12:25 Comment(0)
L
0

you can change rotation on Y axis by 180 degrees

android:rotationY="180"
Lindalindahl answered 18/10, 2022 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.