0

I'm working on a custom Android widget that will both positive and negative values as a bar. Since I'm going with a stock look, I thought I'd extend the ProgressBar class and use that as a base for my widget. However, I can't seem to find a way to programatically get a handle on the bar itself (as opposed to the entire drawable or the entire canvas) so that I can set the start of the Rect to the middle of the bar.

The effect I'd like to achieve is something like this (showing a negative value, if it were positive obviously it would be going the other way).

two way progress bar

I've already overridden the progress setters to check if we've stored a negative value:

private boolean isNegative;

@Override
public void setProgress(final int progress) {
    isNegative = progress < 0;
    super.setProgress(Math.min(Math.abs(progress), this.getMax()));
}

@Override
public int getProgress() {
    return (isNegative ? -1 : 1) * super.getProgress();
}

It's really just drawing the thing that I can't figure out. This only needs to target the latest API (19 as of this post).

Sam Whited
  • 6,880
  • 2
  • 31
  • 37

1 Answers1

3

Maybe it's too late to answer, but you could use two ProgressBar, set the first to be right to left with progressBar.setRotation(180); and then treat them independently, updating both when your status changes.

kauron
  • 95
  • 7
  • Not exactly what I wanted, but sometimes simple hacks aren't such a bad thing. Silly though it sounds, I didn't even think to do it this way (and went with a completely custom job). Thanks. – Sam Whited Feb 25 '15 at 22:20