1
我正在以編程方式填充TableLayout中的行。每行包含3個TextView,但它們水平對齊,我希望它們垂直。Android - 以垂直對齊的項目編程添加TableRows
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("[email protected]");
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);
..但是這不是它,顯然。有任何想法嗎??