hanafey (18) [Avatar] Offline
<< Page 171 quote
We're pretty good at fixing things aren't we. Wait, what? Oh you noticed the skewed
background image, right. We didn't fix that, but you can do it, now that you know how 9-
patch drawables work

If you substitute film_bg_fixed.9.png for film_bg.png the window title and the movies ListView gets squeezed into a tiny region, and basically the layout is so screwed up the app is broken.

This problem is not helped by the draw9patch tool because when it shows the content view for film_bg_fixed.9.png it suggests the content region covers the entire stretched image. Frankly this is the logical behavior that one would expect without any explicit padding in the nine-patch.

But the problem is without any explicit padding defined with black lines in the bottom and right edges, Android uses the top most left black line and the left most top line to define the padding! (This is actually documented to some degree in the official docs).

Only by explicitly drawing a long black line on the bottom and right edges of the nine-patch does the film background image stretch without distorting the image part, and also not constrain the root view of the window to some ridiculously small part of the window.

I think the book should clarify these points because the way this fails is quite confusing.

I also wonder if there is a way to indicate to the root view of the window (which is a linear layout) that it should ignore the padding suggested by the nine-patch by explicitly specifying android:padding="0"?
matthias.kaeppler (8) [Avatar] Offline
Re: Nine Patch Padding Confusion
Sorry for not answering this earlier. I wanted to get the remaining chapters done first, and then start revising based on reviewer's feedback.

Thanks for this hint. The film_bg_fixed was just me messing around, and I never actually meant to commit that, since it's also not mentioned in the book. You are absolutely right about your remark how Android uses the stretch area for padding unless defined.

I will remove the film_bg_fixed image from the sample projects (it's broken and not even used in there and never mentioned) and will add a gotcha note about this.