0

I need a progress bar displaying progress from right to left or from left to right depending on variable. I have also text in the middle of the bar. For all that, I am using a custom class. For rotating the bar, I followed this thread but somehow either the text is not displayed, or it is rotated, or everything disappears from the view...

Code without rotation:

protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // draw text
    }

I have a property positive telling whether to start from left or from right. It would be easy, if I didn't had the text, I would simply call setRotation() somewhere in the code, but now I am trying to rotate the canvas and I can't manage it to bring everything in the correct order. Can someone help me?

Community
  • 1
  • 1
Antiohia
  • 1,142
  • 13
  • 37

1 Answers1

0

I just found it out. Using this thread, I ended up with the following code:

protected synchronized void onDraw(Canvas canvas) {
    canvas.save();
    if(!positive) {
        int cx = this.getMeasuredWidth() / 2;
        int cy = this.getMeasuredHeight() / 2;
        canvas.scale(-1f, 1f, cx, cy);
    }
    super.onDraw(canvas);
    canvas.restore();
    // draw text
}

I have no idea why rotation doesn't work for me but the scale method works fine.

Community
  • 1
  • 1
Antiohia
  • 1,142
  • 13
  • 37