I want to generate dynamically and display an image which is an
indicator of some percentage value, i.e. a rounded rectangle inside a
slightly larger rounded rectangle, and the inner one might be say 2/3
the way along the length of the outer one, indicating roughly 66% in a
visual way. It doesn't need to be an actual progress bar - there's no
movement or anything, and there will just be one of these in every row
of my ListView indicating some percentage value I get from a database.
I've currently got an ImageView defined in an xml layout, and I've set
the background (android:background) to be a drawable which is defined
by a <shape android:shape="rectangle"> in a drawable xml file. This
is easy because each row will have the same length background, e.g. a
grey rectangle stretching all across all 100%.
Then for the foreground which indicates the percentage, I can set the
source (android:src) to be a drawable defined in a different xml file,
but I can't see how I can dynamically (from the java code) set the
length of this rectangle. I've also tried constructing the foreground
image from code by passing a RoundRectShape to a ShapeDrawable and
setting the ShapeDrawable onto the inflated ImageView, but I'm a bit
hazy on this method and in my experiments so far I don't end up with
any foreground image at all.
What's the best way to accomplish this? It seems like it should be a
pretty straightforward task so I have a suspicion I'm going about it