Spi*_*ams 128 android android-layout android-tablelayout
我在Android中使用TableLayout.现在我有一个TableRow,里面有两个项目,在它下面是一个TableRow,它有一个项目.它呈现如下:
-----------------------------
| Cell 1 | Cell 2 |
-----------------------------
| Cell 3 |
---------------
Run Code Online (Sandbox Code Playgroud)
我想要做的是让Cell 3延伸到两个上部单元格,所以它看起来像这样:
-----------------------------
| Cell 1 | Cell 2 |
-----------------------------
| Cell 3 |
-----------------------------
Run Code Online (Sandbox Code Playgroud)
在HTML中我会使用COLSPAN ....如何在Android中使用它?
Sep*_*phy 189
似乎有一个属性在做: layout_span
更新:此属性必须应用于TableRow的子项.不是TableRow本身.
Mar*_*ues 91
只是为了完成答案,必须将layout_span属性添加到子项,而不是TableRow.
这个片段显示了我的tableLayout的第三行,它跨越了2列.
<TableLayout>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="@string/create" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
Oni*_*sha 34
这就是你以编程方式进行的方式
//theChild in this case is the child of TableRow
TableRow.LayoutParams params = (TableRow.LayoutParams) theChild.getLayoutParams();
params.span = 2; //amount of columns you will span
theChild.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)
Rag*_*dra 26
您必须使用layout_weight来填充整行,否则它仍然填充表格布局的左列或右列.
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_weight="1"
android:text="ClickMe" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
也许这会对某人有所帮助.我尝试了解决方案,layout_span
但这不适合我.所以我用这个技巧解决了这个问题.只需用LinearLayout
它代替TableRow
你需要colspan的地方,就是这样.
归档时间: |
|
查看次数: |
88377 次 |
最近记录: |