在我的Android应用程序中,有一个屏幕,其中包含一些要以表格格式显示的数据.该表将包含约5列和至少50行.
如何在android中创建表格?
我进行了搜索,似乎每个人都建议为每个单元格使用TableLayout和textView.由于存在许多textView组件,因此使用此技术似乎有点困难.
还有其他解决方案吗?
解决方法:
TableLayout lTableLayout;
lTableLayout = (TableLayout)findViewById(R.id.tblayout);
for(int i=0;i<10;i++){
TableRow tr1 = new TableRow(this);
tr1.setPadding(0, 5, 0, 0);
lTableLayout.addView(tr1, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
TextView tv11 = new TextView(this);
tv11.setPadding(2, 0, 0, 0);
tv11.setTextSize(12);
tr1.addView(tv11,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); // Can give width and height in numbers also.
}
这些将在采用的表格布局中创建10行和每行1个textview.
在您的xml文件中采用一种表格布局,如下所示:
android:id="@+id/tblayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
标签:android-tablelayout,android
来源: https://codeday.me/bug/20191201/2081387.html