Monday, July 30, 2012

[android-developers] Set bounds for one layer of LayerDrawable?

I'm creating a custom View that looks like a horizontal ProgressBar but doesn't always have to touch the left edge. My approach is to use a LayerDrawable in which one layer uses different bounds (computed at run time). The attachement shows expected (top) versus actual (bottom) results.

From what I can tell, setting the bounds for one layer also sets the bounds for the entire LayerDrawable. The code in the custom View is essentially this:

int left, top, right, bottom;
/*... do some math ... */
Drawable d = mDrawable.findDrawableByLayerId(;
d.setBounds(left, top, right, bottom);

Meanwhile, the xml for the drawable is this:

<layer-list xmlns:android="" >
<shape android:shape="rectangle" >
<solid android:color="#ff999999" />

Can I set bounds for an individual layer without affecting the other layers? If not, what can I do to get around this issue?

You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment