【发布时间】:2018-04-21 08:03:16
【问题描述】:
我正在尝试在以编程方式生成的表格行布局中添加线性布局。线性布局似乎从未显示。我已经尝试在程序中设置宽度和高度,但没有任何帮助。
TableLayout ll = (TableLayout) view.findViewById(R.id.info_table);
TableRow row=new TableRow(getContext());
row.setBackgroundColor(RED);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=20;
int topMargin=20;
int rightMargin=20;
int bottomMargin=10;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
row.setLayoutParams(tableRowParams);
TextView address = new TextView(getContext());
address.setMinimumWidth(320);
address.setMaxWidth(320);
address.setText("Rating");
address.setTypeface(null, Typeface.BOLD);
address.setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
row.addView(address);
View dummyView = new View(getContext());
LinearLayout.LayoutParams dummyParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,300);
dummyParams.weight = 1f;
dummyView.setLayoutParams(dummyParams);
dummyView.setBackgroundColor(Color.BLACK);
row.addView(dummyView);
row.bringChildToFront(dummyView);
ll.addView(row,0);
我只能看到由行设置的红色,但看不到由布局设置的黑色。
【问题讨论】:
标签: android android-layout android-linearlayout android-tablelayout