In the end I was probably overthinking this. I ended up just using a
ShapeDrawable and modifying its bounds to get the desired effect.
Hence, my onDraw method of my custom View looks like this (assuming
that percentage is the relative width of the progress bar I wish to
display):
protected void onDraw(Canvas canvas) {
LayoutParams layoutParams = getLayoutParams();
maxHeight = layoutParams.height - (2 * padding);
maxWidth = layoutParams.width - (2 * padding);
width = StrictMath.round(percentage * maxWidth / 100);
mRect = new Rect(padding, padding, padding + width, padding +
maxHeight);
mShapeDrawable.setBounds(mRect);
canvas.save();
mShapeDrawable.draw(canvas);
canvas.restore();
}
cheers,
Ian
On Dec 30 2008, 8:58 am, androidian <[email protected]> wrote:
> Anybody?
>
> On Dec 28, 11:57 pm, androidian <[email protected]> wrote:
>
> > Hi,
>
> > Can someone tell me how to use the ScaleDrawable class? In particular,
> > instantiating it. There is only one constructor:
>
> > public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth,
> > float scaleHeight)
>
> > ...but it has no supporting javadoc documentation. What is the gravity
> > constant I must pass? I guess I want the drawable which is contained
> > in the ScaleDrawable to appear pretty much to the left of the canvas,
> > with perhaps a bit of padding. What should the scaleWidth and
> > scaleHeight values be? I know from the description of the class that
> > this is the right one for my purpose (to display a static, non-moving
> > progress-bar-like image) but I can't work out how to do this. Let's
> > say the view that contains this image is 150px x 30px and i want the
> > progress to show 1/3, how do I use ScaleDrawable to do this?
>
> > cheers,
> > Ian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---