我正在尝试在Android应用程序中显示一个电子表格,其中每个列都应该被线条包围,并且可以自动调整列宽。我使用了Table Layout,数据以表格格式显示,但我不知道如何为每列添加线条并进行自动调整。如果有人知道,请帮助我。
我正在尝试在Android应用程序中显示一个电子表格,其中每个列都应该被线条包围,并且可以自动调整列宽。我使用了Table Layout,数据以表格格式显示,但我不知道如何为每列添加线条并进行自动调整。如果有人知道,请帮助我。
您可以为TableLayout
设置背景颜色,并为TableRow
添加边距:
<TableLayout android:background="#000000">
<TableRow android:background="#ffffff" android:layout_margin="3dip">
<!-- etc. -->
使用TableLayout.LayoutParams或TableRow.LayoutParams。它们继承了ViewGroup.MarginLayoutParams,这似乎是你需要的。
一个使用TableRow.LayoutParams的示例代码可能如下:
// you can also init values for width, height and weight here
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.setMargins(LEFT_MARGIN, TOP_MARGIN, RIGHT_MARGIN, BOTTOM_MARGIN);
TextView textView = new TextView(this);
textView.setText("I'm in the table");
TableRow row = new TableRow();
row.addView(textView, params);
当您向表格布局添加内容时,可以使用TableLayout.LayoutParams应用相同的原则。
View
的setBackgroundColor
和MarginLayoutParams.setMargins
方法,在代码中实现相同效果。 - Josef Pfleger