【问题标题】:Android, setting column sizes in TableLayoutAndroid,在 TableLayout 中设置列​​大小
【发布时间】:2013-03-01 16:36:59
【问题描述】:

所以,我通过扩展布局文件从代码创建 TableLayout。我试图让第一行跨越两列,下一行包含两个 TextView:键和值。问题是该值可能很长,所以我在 TableLayout xml 中使用设置android:stretchColumnsandroid:shrinkColumns。现在 Key 列和 Value Column 看起来不错,但首先,跨度,标题比屏幕尺寸更宽。

我的文件的当前情况如下:

tale_row.xml:

 <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingTop="5dp"
     android:paddingBottom="5dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp" >
        <TextView 
            android:id="@+id/key"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/gray"
            android:textStyle="bold"
            android:layout_marginRight="10dp" />
        <TextView 
            android:id="@+id/value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/black" />"
 </TableRow>

header_row.xml:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView 
        android:id="@+id/header"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_span="2"
        style="@style/group_separator_style"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" />

</TableRow>

table.xml:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1" >
</TableLayout>

任何想法,可能是什么原因?将属性 clipChildrenclipToPadding 设置为 true 没有帮助。

【问题讨论】:

  • 在标题单元格中使用 layout_width="match_parent"
  • 不幸的是,它没有帮助

标签: android tablelayout


【解决方案1】:

看起来设置android:stretchColumns="1"android:shrinkColumns="1"解决了这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多