我需要带分隔符的表格布局对于每一列。我有八个文本视图,每行有固定宽度,高度取决于网络数据,如果一个文本视图可以有超过千字,另一个可以有单个字。空白区域没有填写文本视图背景,这对我没有帮助。我找不到列分隔符的解决方案。任何人都可以帮我帮我分栏,对不起我的英语不好。
// outer for loop
for (int i = 1; i <= rows; i++) {
final TableRow row = new TableRow(getActivity());
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// row.setBackgroundResource(R.drawable.cell_shape);
row.setPadding(10, 10, 10, 10);
row.setWeightSum(10);
// inner for loop
for (int j = 1; j <= cols; j++) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
final DataBaseHelper myDbHelper = new DataBaseHelper(getActivity());
final Login l = myDbHelper.getLogindb();
// System.out.println(height + "\"" + width + "\"");
final TextView tv = new TextView(getActivity());
tv.setClickable(true);
tv.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, (float) 1.45));
tv.setGravity(Gravity.LEFT);
tv.setText("");
}
}
答案 0 :(得分:0)
您可以在每个单元格的背景字段上使用xml drawable资源。
例1:
抽拉/ cell_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#000"/>
<stroke android:width="1dp" android:color="#ff9"/>
</shape>
布局/ table.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:id="@+id/table" android:layout_width="match_parent" android:layout_height="match_parent"></TableRow>
<TableLayout android:id="@+id/table_se" android:layout_height="match_parent" android:layout_width="match_parent">
<TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:background="@drawable/cell_background" android:padding="5dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="@drawable/cell_background" android:padding="5dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="@drawable/cell_background" android:padding="5dp" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
例2:
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" android:background="#ff0000">
<TableRow android:background="#00ff00" android:layout_margin="2dip">
<Button android:id="@+id/button" android:text="+" android:background="#0000ff" android:layout_margin="2dip"/>
<TextView android:text="@string/label" android:background="#0000ff" android:layout_margin="2dip"/>
<TextView android:id="@+id/amount" android:background="#0000ff" android:layout_margin="2dip"/>
</TableRow>
有关详情:Refer here
修改强>
对于列分隔符
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:stretchColumns="*"
android:padding="5dip"
android:divider="@drawable/tracking_green"
android:showDividers="middle"
>