Reputation: 1125
I have a TextView and an EditText in a RelativeLayout. I'd like to create a border behind them with a white background, like a card. I have a few more complex examples, with images and text as well.
The only way I can think of to do this is to introduce multiple nested ViewGroups (say another RelativeLayout), so each card is a ViewGroup which contains the two other Views, and automatically sizes correctly and has a border set.
However, this ends up with a view hierarchy like:
etc
Which seems excessive and potentially problematic, particularly if I end up having nested cards.
Apart from changing the RelativeLayouts for LinearLayouts (which I imagine won't have a large impact), is there any way of simplifying this layout hierarchy?
Upvotes: 0
Views: 127
Reputation: 5872
I think it is ok according to Google to have up to 6 or 7 nested layouts without a need to worry.
Think of the gmail application. each mail is consisted of (at least 1) ViewGroup that is displayed in a listView which is probably nested inside another (at least 1) ViewGroup...
In short, I think your hierarchy is ok
Upvotes: 1