如何在Android中设置表的宽度和列数在TableLayout [英] How to set Table width and number of Columns in TableLayout in Android

查看:650
本文介绍了如何在Android中设置表的宽度和列数在TableLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里,使表像Android的HTML,我可以连续设置列宽正如我们在HTML

Is there and any method to make table like html in android where i can set row column width as we do in html

<table >
<tr><td style="width:'50%;"></td>
    <td style="width:'50%;"></td>
</tr>
</table>


<TableLayout
           android:id="@+id/tableLayout1"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:stretchColumns="3" >
           <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
           </TableRow>
           <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
           </TableRow>
</TableLayout>


编辑1:

有关的东西,如HTML那里的百分比宽度就工作到其父

For something like Html there the percentage width works with respect to its Parent

但在Android的推出了重量方面的工作,以适用于屏幕尺寸
根。

but the weight introduced in Android works with respect to the screen size available for root.

推荐答案

您可以使用的LinearLayout和权重属性才达到这一点。

You can use a LinearLayout and the weight attribute to achive this.

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0">

在行的子元素可以各自被给予权重的总和(百分比)的一部分。一定要设置layout_width为0dp

The child elements in your Rows can each be given a weight as a portion of the sum (a percentage). Be sure to set the layout_width to "0dp"

<Button 
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.5" />

<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.5" />

看看这个previous问题
线性布局和体重的Andr​​oid

这篇关于如何在Android中设置表的宽度和列数在TableLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆