Android TableLayout:保留不同表格之间的列宽度

发布于 2024-09-12 10:33:50 字数 928 浏览 3 评论 0原文

我的视图中有两个 TableLayout,一个在另一个之上。我希望它们作为一个表格来计算列宽,但出于美观原因,它们之间有间隙(并且主视图背景显示出来)分开显示。

每个表都有 3 列,我希望根据内容自动调整列宽,但我只希望两个表中的列能够很好地对齐,宽度相同。

目前我的表格看起来像这样:

+---------------------------+
|      |                |   |
|      |                |   |
+---------------------------+

+---------------------------+
|          |            |   |
|          |            |   |
|          |            |   |
|          |            |   |
+---------------------------+

但我希望它们看起来像这样:

+---------------------------+
|         |             |   |
|         |             |   |
+---------------------------+

+---------------------------+
|         |             |   |
|         |             |   |
|         |             |   |
|         |             |   |
+---------------------------+

我能看到得到我想要的东西的唯一方法是对问题中的列应用固定宽度,但这违背了拥有 TableLayout 的意义帮我算一下宽度。

这有可能吗?

I have two TableLayouts, one above the other, in my View. I want them to act as a single table for the purpose of calculating column widths, but appear separately with a gap between them (and the main View background showing through) for aesthetic reasons.

Each table has 3 columns, and I want the column widths sized automatically depending on content, but I just want the columns to line up nicely with the same widths in both tables.

At the moment my tables look like this:

+---------------------------+
|      |                |   |
|      |                |   |
+---------------------------+

+---------------------------+
|          |            |   |
|          |            |   |
|          |            |   |
|          |            |   |
+---------------------------+

But I want them to look like this:

+---------------------------+
|         |             |   |
|         |             |   |
+---------------------------+

+---------------------------+
|         |             |   |
|         |             |   |
|         |             |   |
|         |             |   |
+---------------------------+

The only way I can see of getting what I want is to apply a fixed width to the columns in questions, but that defeats the point of having the TableLayout calculate the widths for me.

Is it at all possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

物价感观 2024-09-19 10:33:50

你应该认真考虑作弊。坚持与您的背景看起来相同的表格行,没有人会知道它不是两个之间有间隙的表格。您可能需要对边框进行一些摆弄,但我怀疑这不仅是可能的,而且比链接两个独立的表对象更容易。

You should seriously consider cheating. Stick in a table row that looks identical to your background, and nobody will know that it isn't two tables with a gap between them. You may have to do some fiddling with borders, but I suspect that it's not only possible, but easier than linking two independent table objects.

偷得浮生 2024-09-19 10:33:50

我不确定这是否适用于所有情况,但您可以尝试设置作为表格单元格的 3 个组件的布局权重。如果您在每列上使用相同的重量,它们最终应该具有相同的尺寸。

例子:
安卓:layout_weight =“0.5”

I'm not sure if this works in every case but you could try setting layout weight of the 3 components you have as table cells. If you use same weight on each column they should endup same size.

example:
android:layout_weight="0.5"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文