【问题标题】:Help create TableLayout inside .java activity帮助在 .java 活动中创建 TableLayout
【发布时间】:2010-11-16 22:18:19
【问题描述】:

我在活动中创建表格布局时遇到问题。到目前为止,我设法使用 textview 显示结果查询。

( (TextView) view.findViewById(R.id.tv_id) ).setText( listItem.getId()+""); 
( (TextView) view.findViewById(R.id.tv_name) ).setText( listItem.getName() ); 
( (TextView) view.findViewById(R.id.tv_age) ).setText( listItem.getAge()+"" );

如果你能帮我把这个文本视图变成表格布局,我将不胜感激。

感谢您的帮助

【问题讨论】:

    标签: android android-activity tablelayout


    【解决方案1】:

    您需要在布局 xml 中执行此操作。如果这是活动的唯一输出,则 xml 将类似于:

    <Table_Layout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretch_columns="*">
    
    <TableRow>
    <TextView
    android:id="@+/tv_id"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"/>
    <TextView
    android:id="@+/tv_name"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"/>
    <TextView
    android:id="@+/tv_age"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"/>
    </TableRow>
    
    </Table_Layout>
    

    如果有更多的行,将其全部包装在一个 ScrollView 中,这样 ui 就可以滚动了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2011-02-15
      相关资源
      最近更新 更多