TableLayout mTableLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTableLayout = findViewById(R.id.table_layout);
mTableLayout = new TableLayout(this);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.black);
TableRow tableRow = new TableRow(this);
tableRow.addView(imageView);
mTableLayout.addView(tableRow);
我想在表格行中添加一个图像视图,然后将该表格行添加到表格布局中。但在此运行时,屏幕上什么也没有发生。我也不知道为什么。我试图找到Logcat和断点,但没有任何问题。
发布于 2018-05-28 20:06:17
Ok the issue here is you are creating row first the the table layout; try adding row to layout first then view to row like below reference code:
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
tv.setText("This is text");
tl.addView(row);
row.addView(tv);
https://stackoverflow.com/questions/50565986
复制相似问题