【问题标题】:How to set view's layout column in code (view is inside tablerow)?如何在代码中设置视图的布局列(视图在 tablerow 内)?
【发布时间】:2011-05-28 02:56:16
【问题描述】:

我在 xml 中有一个表格布局。我还在代码中添加了一些行。如何在代码中设置某些视图的 column_layout?

在xml中我有:

android:layout_column="3"

如何在代码中实现相同的功能(例如 TextView)?

【问题讨论】:

    标签: android tablelayout tablerow


    【解决方案1】:
            TextView tv = new TextView(this); 
            tv.setLayoutParams(new TableRow.LayoutParams(3));
    

    【讨论】:

      【解决方案2】:

      我不完全确定我理解了这些问题,但是 MyTracks for Android 使用表格布局提供了一些很好的示例代码。可以找到here

      感谢您的评论。我认为这就是你要找的:

      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:stretchColumns="3">
      
      <TableRow>
          <TextView
              android:layout_column="1"
              android:text="Open..."
              android:padding="3dip" />
          <TextView
              android:text="Ctrl-O"
              android:gravity="right"
              android:padding="3dip" />
          <TextView
              android:text="String"
              android:gravity="right"
              android:padding="3dip" />
      </TableRow> ...`
      

      【讨论】:

      • 我需要将 textview 放到代码中 tablerow 内的第 3 列。在 xml 中,这是通过“android:layout_column”属性完成的。
      • 我需要做你在java代码(不是xml)中发布的同样的事情,对不起我的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2017-10-16
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      • 2011-09-18
      • 2021-01-30
      相关资源
      最近更新 更多