[英]Android - Grouping layouts and views
我需要一些有关如何最好地在Android中实现UI的建议。
我想要一个容器清单。 每个容器有7个项目,如下所示。 项目5-7是具有两个文本元素的子容器。
我在想一个LinearLayout
,其中包含RelativeLayouts
的列表。 那很清楚。 至于如何在RelativeLayout
布置元素,我不太确定。
关于如何切片的任何建议? 将布局和视图组合在一起的最有效方法是什么?
谢谢!
我认为您应该将ListView与可扩展自定义行的适配器一起使用。
对于我自己的行,我个人将使用1个父级RelativeLayout,并将所有子级直接直接对齐其中。 但是,如果您愿意,可以使用一些LinearLayouts来实现。
如果您每个人都需要用不同或更多的数据(行)来填充列表,则不仅可以以这种方式构建它,而且使布局变得相当容易,而且还使您有机会使列表动态化。
我还没有测试过这段代码,我知道它看起来很混乱,但是自从我曾经尝试过,因为我曾经写过一个布局几乎相似的自定义ListView,所以我个人会尝试一下。
<RelativeLayout>
<TextView> //position at top
Lorem ipsum dolor sit amet, consectetur adipisicing...
</TextView>
<TableLayout> //stretchcolumns = 2 && position at bottom
<TableRow>
<RelativeLayout>
<TextView>
Lorem Ipsum //position at top
</TextView>
<ImageView>
icon //position to left
</ImageView>
<TextView>
Lorem Ipsum //position to right
</TextView>
<RelativeLayout>
</TableRow>
<TableRow>
<TableLayout> //stretchcolumns = 3
<TableRow> //give all children a weight of 1
<RelativeLayout>
<TextView>
1234 //position at top
</TextView>
<TextView>
Lorem Ipsum //position at bottom
</TextView>
</RelativeLayout>
<RelativeLayout>
<TextView>
1234 //position at top
</TextView>
<TextView>
Lorem Ipsum //position at bottom
</TextView>
</RelativeLayout>
<RelativeLayout>
<TextView>
1234 //position at top
</TextView>
<TextView>
Lorem Ipsum //position at bottom
</TextView>
</RelativeLayout>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout></RelativeLayout>
您可能会考虑使用GridLayout ,这里提供了它的概述: http : //android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
它是在API级别14(Android 4.0)中引入的,但向下兼容API级别7的向后端口是Android支持库的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.