简体   繁体   English

是否可以仅制作窗口小部件而制作Android版图?

[英]Is it possible to make an Android Layout, without just widgets?

Just something I have been thinking about. 只是我一直在想的事情。 It is possible to create an android layout with just a TextView widget and no Layout code (eg: inearLayout, ScrollLayout), but if I try to add anything else to the XML file all sorts of errors start popping up. 可以仅使用TextView小部件而不使用布局代码(例如:inearLayout,ScrollLayout)创建android布局,但是如果我尝试将其他内容添加到XML文件中,则会出现各种错误。 Is it possible to create a Layout with just widgets? 是否可以仅使用窗口小部件来创建布局?

Also, if it is, how? 另外,如果是,怎么办?

I don't think it's possible inside of an XML layout to have a layout of purely widgets and no ViewGroups. 我认为在XML布局内部不可能有仅包含小部件且没有ViewGroups的布局。 You would for one be creating an invalid XML doc (multiple roots since a widget cannot contain other widgets). 您可能会创建一个无效的XML文档(多个根,因为一个小部件不能包含其他小部件)。 Also you need a ViewGroup to hold multiple Views. 另外,您还需要一个ViewGroup来容纳多个View。 You can create a merge and then decide on the view group later, however that is just a substitute for a ViewGroup. 您可以创建一个合并,然后在以后决定视图组,但这只是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. 但是,这是最接近XML布局的东西,其中只有小部件,周围是merge元素作为xml根标签。

Yes it is possible to create layout with a single View (eg TextView ). 是的,可以使用单个 View (例如TextView )创建布局。 But if multiple Views are required you neeed to wrap them with a ViewGroup (eg LinearLayout ) 但是,如果需要多个视图,则需要用一个ViewGroup包裹它们(例如LinearLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM