views:

35

answers:

2

Just something I have been thinking about. It is possible to create an android layout with just a TextView widget and no Layout code (e.g: inearLayout, ScrollLayout), but if I try to add anything else to the XML file all sorts of errors start popping up. Is it possible to create a Layout with just widgets?

Also, if it is, how?

+3  A: 

I don't think it's possible inside of an XML layout to have a layout of purely widgets and no ViewGroups. You would for one be creating an invalid XML doc (multiple roots since a widget cannot contain other widgets). Also you need a ViewGroup to hold multiple Views. You can create a merge and then decide on the view group later, however that is just a substitute for a ViewGroup. However it is the closest thing to an XML layout with only widgets in it, surrounded by a merge element as the root xml tag.

Greg
Cool. Thanks for the explanation
TehGoose
+1  A: 

Yes it is possible to create layout with a single View (e.g. TextView). But if multiple Views are required you neeed to wrap them with a ViewGroup (e.g. LinearLayout)

cement
Oh ok. Thanks :)
TehGoose