简体   繁体   English

如何在Android中跨列和拉伸列

[英]How to span and stretch columns in Android

I'm relatively new to Android and what I want to achieve is a table/grid type layout with multiple rows. 我是Android的新手,我想要实现的是具有多行的表/网格类型布局。 Column 2 onwards should always be aligned horizontally or for rows with less columns for them to stretch to the width of the container. 从第2列开始,应始终水平对齐,或者在列数较少的行中对齐,以使其延伸到容器的宽度。 ie in the example below the textbox on line 1 stretches across to fill column 2 and 3 (eg on my android phone the width of the screen) 即在下面的示例中,第1行的文本框延伸至填充第2列和第3列(例如,在我的android手机上,屏幕的宽度)

-------------------------------------
|label        | textbox............ |
|longer label | textbox..  | button |
|-----------------------------------|

Kind of thing. 之类的事情。 I tried with a table, which works, but I cannot span columns. 我尝试了一个可以工作的表格,但无法跨列。 All I could find was android:layout_span on some website but that doesn't seem to be available (well, to Eclipse anyway). 我只能找到某个网站上的android:layout_span,但似乎不可用(无论如何,对于Eclipse)。

Maybe table isn't the right layout, but that's all I could find to allow me to align columns. 也许表格不是正确的布局,但这就是我可以找到的所有使列对齐的方法。 I'd prefer to have it all in the layout XML rather than coding it. 我宁愿将它们全部放在布局XML中,而不是对其进行编码。

Did you try having a few horizontal linear layout within one vertical linear layout ? 您是否尝试过在一种垂直线性布局中包含一些水平线性布局? It might make your XML file a little bit longer, but it may also solve the issue. 它可以使您的XML文件更长一些,但也可以解决该问题。

Rule of thumb: Don't trust Eclipse's interpretation of the interface. 经验法则:不要相信Eclipse对接口的解释。 It's not always right. 这并不总是正确的。

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

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