7

I have a custom built circular progress bar used for a seconds counter on a clock, which I'd like to flip, so that the clock is counting counter-clockwise.

Searching here for a solution, I found this:

Right to Left ProgressBar?

Which obviously works for a horizontal progress bar, but I can't simply rotate it 180 degrees, since that will just move the clock 180 degrees and it will still be ticking clockwise.

Is there any other way to mirror a ProgressBar, or any View?

Edit:

Just found "android:rotationY" and the programmatic equivalent, but this ideally needs to be for 2.2 and above..

Mahozad
  • 18,032
  • 13
  • 118
  • 133
  • This is not really an answer, but would you consider open sourcing the circular progressbar? I've seen a lot of requests for it. – Raghav Sood Dec 24 '12 at 13:59
  • This is how I originally did it: http://stackoverflow.com/questions/12776587/android-circular-determinate-progressbar/12905405 but a lot has changed on it since then. I can put together a sample application on github after the holidays! –  Dec 24 '12 at 16:35
  • Does this answer your question? [Android custom circular ProgressBar direction](https://stackoverflow.com/questions/44884317/android-custom-circular-progressbar-direction) – Mahozad Jan 08 '21 at 10:11

3 Answers3

9

I was able to flip ProgressBar simply with attribute scaleX in XML:

android:scaleX="-1"

This works for other View as well.

Micer
  • 8,731
  • 3
  • 79
  • 73
2

Extend ProgressBar in the same way you would for a horizontal progress bar, but in the onDraw method, flip the canvas rather than rotate it:

public class InverseProgressBar extends ProgressBar {

public InverseProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public InverseProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public InverseProgressBar(Context context) {
    super(context);
}

@Override
protected synchronized void onDraw(Canvas canvas) {
    canvas.scale(-1f, 1f, super.getWidth() * 0.5f, super.getHeight() * 0.5f);
    super.onDraw(canvas);
}

}
0

Yes. In newer versions of material design library, the circular progress bar can be mirrored:

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

Refer here for more info.

Mahozad
  • 18,032
  • 13
  • 118
  • 133