0

以编程方式创建了一个表布局。它看起来像这样。在此处输入图像描述

在这里,我想在每行后面添加水平线,如何通过编程实现。创建表格布局的示例代码

ScrollView ScrollView=新建ScrollView(this);TableLayout resultLayout=新表布局(this);resultLayout.setStretchAllColumns(true);resultLayout.setShrinkAllColumns(true);TableRow tablerowMostRentVehicle=新TableRow(this);表格rowMostRecentVehicle.setGravity(Gravity.CENTER_HORIZONTAL);TextView textViewMostRentVehicle=新文本视图(this);textViewMostRecentVehicle.setText(“最新车辆详细信息”);textViewMostRecentVehicle.setTextSize(类型值.COMPLEX_UNIT_DIP,12);textViewMostRecentVehicle.setTypeface(字体.SERIF,字体.BOLD);tablerowMostRecentVehicle.addView(textViewMostRentVehicle);// ...resultLayout.addView(表格最新车辆);resultLayout.addView(表格行注册标记);resultLayout.addView(tableRowMakeModel);resultLayout.addView(tableRowColour);resultLayout.addView(tableRowChasisNo);resultLayout.addView(表格行首次使用日期);resultLayout.addView(tableRowTypeofFuel);// ...

4个答案4

重置为默认值
1

使用此代码。

视图视图=新视图(this);view.setBackgroundResource(R.drawable.line);resultLayout.addView(视图);

在每个表行之后添加此代码。

1

我需要添加view.setLayoutParams(新LayoutParams(LayoutPartams.MATCH_PARENT,1));对于@dipali的回答:

视图视图=新视图(this);view.setLayoutParams(新LayoutParams(LayoutPartams.MATCH_PARENT,1));view.setBackgroundColor(Color.GRAY);tablerowMostRecentVehicle.addView(视图);
0

R.drawable.row_border:

<?xml version=“1.0”encoding=“utf-8”?><shape xmlns:android=“http://schemas.android.com/apk/res/android" ><solidandroid:color=“#ffffff”/><stroke android:width=“3dp”android:color=“#99cc00”/></形状>

然后:

tbrow.setBackgroundResource(R.drawable.row_borders);
0
视图视图=新视图(this);view.setBackgroundColor(Color.GRAY);tablerowMostRecentVehicle.addView(视图);

我希望它对你有用。

你的答案

单击“发布您的答案”,表示您同意我们的服务条款并确认您已阅读我们的隐私政策.