Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom circular ProgressBar direction

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?

like image 554
amitairos Avatar asked Jul 03 '17 11:07

amitairos


2 Answers

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" />
like image 89
tachyonflux Avatar answered Oct 05 '22 05:10

tachyonflux


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.

like image 41
Mahozad Avatar answered Oct 05 '22 07:10

Mahozad