使单元格的宽度和高度相同以填充表格

编程入门 行业动态 更新时间:2024-10-10 11:29:21
本文介绍了使单元格的宽度和高度相同以填充表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试学习如何在 android 中使用表格布局,这是我的代码:

I'm trying to learn how to use table layouts in android, this is my code:

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="schemas.android/apk/res/android" android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 3 columns --> <TableRow android:id="@+id/tableRow3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip" > <TextView android:id="@+id/textView2" android:text="Column 1" /> <Button android:id="@+id/button2" android:text="Column 2" /> <Button android:id="@+id/button3" android:text="Column 3" /> </TableRow> </TableLayout>

这是结果:

如何使 TableRow 适合 TableLayout 的宽度和 TableLayout 的高度?简单来说,我想让所有具有相同宽度的列和具有相同高度的行填充 TableLayout,这可能吗?怎么样?

How can I make the TableRow to fit the width of the TableLayout and the height to the TableLayout height? In simple words, I would like to have all columns with the same width and rows with the same height filling the TableLayout, is it possible? How?

推荐答案

您需要使用 weight 值.两行的 xml 看起来像这样.-

You need to play with weight values. The xml for two rows would look like this.-

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="schemas.android/apk/res/android" android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 3 columns --> <TableRow android:id="@+id/tableRow3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:padding="5dip" > <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 1" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 2" /> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 3" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:padding="5dip" > <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 1" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 2" /> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Column 3" /> </TableRow> </TableLayout>

这就是结果.-

作为旁注,请注意 fill_parent 已弃用,您应该改用 match_parent.

As a side note, notice that fill_parent is deprecated, you should use match_parent instead.

更多推荐

使单元格的宽度和高度相同以填充表格

本文发布于:2023-11-23 01:05:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   单元格   表格   高度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!