在我的 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 文件中采用一个表格布局,如下所示:
<TableLayout
android:id="@+id/tblayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableLayout>
关于android - Android 中的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10026771/