【发布时间】:2016-01-25 14:42:25
【问题描述】:
我正在以编程方式填充 TableLayout 中的行。每行包含 3 个 TextView,但它们是水平对齐的,我希望它们是垂直的。
TableLayout table = (TableLayout) findViewById(R.id.tableLayout_customers);
TableRow row = new TableRow(this);
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView tw_name = new TextView(getApplicationContext());
TextView tw_email = new TextView(getApplicationContext());
TextView tw_phone = new TextView(getApplicationContext());
tw_name.setText("Mr Foo");
tw_email.setText("mrfoo@bar.ninja");
tw_phone.setText("123");
row.addView(tw_name);
row.addView(tw_email);
row.addView(tw_phone);
table.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
我试过这个:
row.setGravity(Gravity.CENTER_VERTICAL);
row.setOrientation(LinearLayout.VERTICAL);
.. 但显然不是这样。有什么想法吗??
【问题讨论】:
标签: android alignment orientation tablelayout tablerow