我正在开发一个应用程序,我在其中以编程方式生成行:
TableLayout tableLayout = (TableLayout) findViewById(R.id.tablelayout);
for(int j=0; j<50; j++){
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for(int i = 0; i<10; i++){
TextView t = new TextView(this);
t.setText("Dynamic TV");
t.setPadding(10, 10, 10, 10);
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(t);
// Added Horizontal line as
View view=new View(this);
view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1));
view.setBackgroundColor(Color.rgb(50, 50, 50));
tableLayout.addView(view);
}
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,0.1f));
}
在这个我插入的水平线但我需要的是:
1。我希望垂直线作为列分隔符,
2. 想要降低水平线的高度。
我尝试了各种方法,但无法完成任务。请指导我如何做到这一点。
答案 0 :(得分:1)
要添加垂直分隔符并设置高度1px,您可以尝试此
TableLayout tableLayout = (TableLayout) findViewById(R.id.tablelayout);
for (int j = 0; j < 50; j++) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for (int i = 0; i < 10; i++) {
TextView t = new TextView(this);
t.setText("Dynamic TV");
t.setPadding(10, 10, 10, 10);
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(t);
// Add vertical separator
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
v.setBackgroundColor(Color.rgb(50, 50, 50));
tableRow.addView(v);
}
// Added Horizontal line as
View view = new View(this);
view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1));
view.setBackgroundColor(Color.rgb(50, 50, 50));
tableLayout.addView(view);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 0.1f));
答案 1 :(得分:0)
请尝试以下代码:
// Added Horizontal line as
View view1=new View(this);
view1.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
view1.setBackgroundColor(Color.rgb(50, 50, 50));
tableLayout.addView(view1);