我需要一些关于如何最好地在Android中实现UI的建议。
我想要一份集装箱清单。每个容器有7个项目,如下所示。第5-7项是具有两个文本元素的子容器。
我在考虑一个包含RelativeLayouts列表的LinearLayout。这一点很明显。至于如何在RelativeLayout中布局元素,我不是很确定。
对如何切片有什么建议吗?将布局和视图组合在一起最有效的方法是什么?
谢谢!

发布于 2012-12-10 02:50:04
我认为您应该使用带有能够膨胀自定义行的适配器的ListView。
对于行,我个人会使用一个父RelativeLayout,并直接在其中对齐我的所有子对象。
以这种方式构建它不仅使布局变得相当容易,而且如果您需要用不同或更多的数据(行)填充列表,还可以让您有机会使列表成为动态的。
发布于 2012-12-10 02:41:36
我还没有测试过这段代码,我知道它看起来有点凌乱,但不假思索,这是我个人会尝试的东西,因为我曾经写过一个布局几乎类似的自定义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>发布于 2012-12-10 02:42:04
您可能会考虑GridLayout,此处提供了它的概述:http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
它是在API level 14 (Android 4.0)中引入的,但一个兼容到API level 7的后端口是Android支持库的一部分。
https://stackoverflow.com/questions/13790260
复制相似问题