I am working on a app where I want to show a quantity in a rectangle. The following is what I need. I have 2 values, say totalMoney and spentMoney.
I want to show the remaining money (i.e. totalMoney – spentMoney) in a rectangle box in 2 colors.
Like this:
|======================|
|///////////| |
|////50%////| |
|///////////| |
|======================|
This rectangle will be in a custom View, in collaboration with other components like textview etc.
How do I get this in Android? I am working on Android 2.2.
You need a ProgressBar.
Here is an example of a custom one.
progressbarlayers is an xml file that defines how I want the progress bar to look. Here is how mine is set up.
It comes out looking like this:
But you can make it look like whatever you need it to.
EDIT: There are many ways you could achieve getting text on to them. If your parent layout is a RelativeLayout you can just stack a TextView on top of the progress bar and call setText on the text view each time the progress is updated. Probably what is a better approach is subclass ProgressBar to draw it on there for you. Here is an example of that. They just made a new View that extends ProgressBar, and override the onDraw to draw some text to the canvas each time as well as painting the bars and background.