trentrosenbaum (6) [Avatar] Offline
Under the section '3.5.2 Technique 8: getting in <shape>' the table labelled 'Table 3.T: Valid elements for defining shape drawables' correctly says that the 'shape' XML element has an attribute called 'android:shape' just like the following android developer page

The following code listings need to be altered

Listing 3.L: Defining shape drawables in XML, (page 115)
Listing 3.L: Drawable definition for a list selector in the pressed state, (section 3.5.3, page 11smilie

These code samples show that the 'shape' XML element can contain 'android:type' as an attribute, but this is not the case.


to be replaced with

trentrosenbaum (6) [Avatar] Offline
Re: Feedback on section 3.5.2 and 3.5.3
I was wondering if the following sentence is a bit confusing?

'A shape drawable is represented internally by the GradientDrawable class (and not ShapeDrawable' as you may have expected) and in XML is defined using the <shape> element'

What is it trying to inform me about? Is it trying to say that under the covers android uses GradientDrawable over the ShapeDrawable class? The android documentation would suggest that the <shape> XML element is used to create the ShapeDrawable class. I did find a few posts that showed it was an area that people were having trouble and so it is good to be in the book. I just feel the sentance needs to be expanded. Any thoughts?
charlie.collins (125) [Avatar] Offline
Re: Feedback on section 3.5.2 and 3.5.3
Same deal here Trent. I am just getting into an editing pass of this chapter, and I'll look at these things carefully. After I am done Matthias (who wrote this section) will make another pass too. We'll both keep in mind the feedback here.

matthias.kaeppler (8) [Avatar] Offline
Re: Feedback on section 3.5.2 and 3.5.3
From my observations, Android creates a GradientDrawable from shapes (not tested if that's true for all kinds though). GradientDrawable does NOT inherit from ShapeDrawable, but is still created using the <shape> element.

Maybe that sentence needs to be revised to: the <shape> element maps to either ShapeDrawable or GradientDrawable, depending on the shape kind.
trentrosenbaum (6) [Avatar] Offline
Re: Feedback on section 3.5.2 and 3.5.3
Yes I totally agree with you about GradientDrawable not inheriting from ShapeDrawable because they both extend Drawable.

I think when I read the sentence this caused me to instantly go to the javadoc for both of those objects. When I did not see this inheritance then I started to wonder why android would create another object when it usually maps XML elements straight to an object equivalent with the same name.

I also found the page at

It only mentions the gradient XML element and then associates the ShapeDrawable object with the shape XML element.

So there seems two pieces of information saying something a bit different. On one side the android docs saying it does create a ShapeDrawable. On the otherside a real world case that you have observed. As a reader I am not sure how this has been observed and so it presents something that is hard to take in.

Do not get me wrong, if this had been observed then I think it is great that the book provides such information, (that real world experience). It might be that the link above is presenting something incorrectly. I just think more clarification is needed.