【问题标题】:How to set Table Column in android如何在android中设置表格列
【发布时间】:2012-01-18 06:45:56
【问题描述】:

我在设置表格行(包含文本视图)的布局参数时遇到了一些困难。

我想添加一些列以获得良好的布局。我正在动态地做它。 (在代码中)

<TableRow> 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ok"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bye"/>
</TableRow>

我希望这两个文本视图成为两列并相应地在屏幕上布局。

【问题讨论】:

  • 发布您的代码并说明您面临的问题类型。
  • 我已经编辑了,请告诉如何根据列进行设置。
  • 你有没有在你的表格布局中使用过这个android:stretchColumns="1"

标签: android android-layout android-tablelayout


【解决方案1】:

您已经编写的内容实际上应该已经创建了两列,问题是它们可能不会像您期望的那样位于屏幕上 - 列将尽可能窄。 Android布局中的TableLayout标签有几个属性。其中之一是拉伸列 - 如果给定所描述的列将被拉伸以填充所有指定的宽度。如果您需要将它们全部均匀拉伸,请使用星号,如果您希望任何特定列被拉伸以覆盖剩余空间,请使用其基于 1 的索引(您可以指定一组索引)。见这里:

<TableLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:stretchColumns="0,1" >
   <TableRow android:layout_width="fill_parent"> 
     <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="ok"    
      />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="bye" />
   </TableRow>
</TableLayout>

顺便说一句,如果您只需要一行,您可以使用 LinearLayout 和orientation="horizo​​ntal" 来做同样的事情。如果您有几行,请记住您实际上是在处理表格 - 列的所有行将正好位于另一列之上,最宽的行将决定列的宽度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    • 2011-06-18
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多