android 格式纵向布局,Android的横向和纵向布局发展

博客内容介绍了如何在Android中结合使用ScrollView和TableLayout来实现一个可滚动的表格布局。通过XML布局文件定义,然后在代码中动态插入行和记录,创建了一个适应屏幕宽度并能填充数据的表格。
摘要由CSDN通过智能技术生成

这不是一个好主意,使用两个滚动视图。但是,如果需要的话,你可以做一两件事:

创建XML布局:

android:id="@+id/scrollview_vertical_table"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

tools:ignore="UselessParent" >

android:id="@+id/tablelayout"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:stretchColumns="*" >

而在这个表中插入记录或行编程为:

TableLayout tableLayoutTransactionLineHeading = (TableLayout) findViewById(R.id.tablelayout);

for(int j=0; j

TableRow tableRow = new TableRow(this);

tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));

TextView lineno = new TextView(this);

lineno.setText(lineNo[j]);

lineno.setPadding(10, 10, 10, 10);

lineno.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

tableRow.addView(lineno);

View v = new View(this);

v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));

v.setBackgroundColor(Color.rgb(50, 50, 50));

tableRow.addView(v);

tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,0f));

}

希望这将帮助你。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值