问题 如何在android中设置表列


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

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

<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>

我希望这两个textviews在屏幕上相应地成为两列和布局。


12918
2018-01-18 06:45


起源

请发布您的代码 - Lucifer
发布您的代码并指定您面临的问题类型。 - jeet
我已经编辑过,请告诉我们如何根据专栏设置它们。 - abhishek ameta
你有没有用过这个 android:stretchColumns="1" 你的桌面布局。 - Praveenkumar
不,我怎么用呢? - abhishek ameta


答案:


你已经写过的东西实际上应该已经创建了两列,那就是它们可能没有像你期望的那样位于屏幕上 - 列将尽可能地缩小。 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”做同样的事情。如果你有几行,请记住你实际上正在处理表 - 列的所有行都将恰好位于另一行之上,最宽的行将决定列的宽度。


16
2018-01-18 08:22