The "include" directive is a way to reuse layout components when creating an Android GUI. When I first used it to make use of a button, I couldn't figure out why the assumed-to-be-overridden "text" property wasn't showing up.
Google's documentation mentions that a "few" of the properties can be overridden, including the layout parameters and the ID. Well, it looks like "text" is one of the ones that cannot be.
Based on a quick look at the source for the android.view.LayoutInflater, it seems that you can override just these properties:
- the layout parameters
- the ID
- the visibility
As for overriding other properties, I guess the relevant inflater could be modified or subclassed to see what is being included, and then override properties for that particular view type if it sees a relevant property for it specified (e.g., the "text" property for a button, which would certainly be convenient in my case), but there might some good reasons not to do that.
Be careful! As noted in the Google's documentation, you've got to specify
both layout_width and
layout_height in your include statement if you want to override the layout dimensions. This is a
noted issue, and Google updated their documentation to reflect it, but there don't seem to be any plans to modify the way
<include> works to address it.
No comments:
Post a Comment