【问题标题】:Spanning columns with TableLayout [duplicate]使用 TableLayout 跨列 [重复]
【发布时间】:2011-08-27 05:57:07
【问题描述】:

可能重复:
What is the equivalent of “colspan” in an Android TableLayout?

它在 TableLayout 的文档中说“单元格可以跨列,就像它们在 HTML 中一样。”但是,我找不到任何方法。

具体来说,我有一行两列,另一行一列。我希望一列行跨越整个表格。看起来很简单,但我没看到。

【问题讨论】:

标签: android android-tablelayout


【解决方案1】:

添加 android:layout_span="3" 以跨越 3 列。 例如:

        <TableRow>
            <Button android:id="@+id/item_id"
                android:layout_span="2"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="item text" />     
        </TableRow>

【讨论】:

  • 啊,在 TableRow.LayoutParams 中:developer.android.com/reference/android/widget/…
  • 查找那些布局 XML 文件很棘手——很容易忘记 android:layout_* 属性在单独的 javadocs 中。
  • -1,当按钮的文本太小时,此解决方案不起作用。例如,当文本只是像计算器应用程序中的 + 时,按钮将不会增长,直到它覆盖两列(如果这两列比没有 columnSpan 的按钮宽)。
  • 为什么我们不能在上面的视图上使用权重,即按钮
【解决方案2】:

android:layout_span 可以解决问题。

示例:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
    <TextView android:id="@+id/info"
        android:layout_span="2"
        android:text="some text"
        android:padding="3dip"
        android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow>
    <TextView android:text="some other text" 
        android:padding="3dip" />
    <TextView android:text="more text" 
        android:padding="3dip" />
</TableRow>
</TableLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    相关资源
    最近更新 更多