0
テーブルレイアウトを実際に行に合わせようとしていますが、画像のボタンが伸び続けている最後の列は、パディングとsetColumnStretchableをfalseに設定しました。以下は私のコードとアプリのUIです...テーブル行の単一の列を整列します。
TableLayout tl = (TableLayout) findViewById(R.id.scrollViewTable);
tl.setColumnStretchable(1,true);
tl.setColumnStretchable(2,true);
tl.setColumnStretchable(3,true);
tl.setColumnStretchable(4,false);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
/* Create a Button to be the row-content. */
TextView prodName = new TextView(this);
TextView unitPrice = new TextView(this);
TextView Quantity = new TextView(this);
TextView total = new TextView(this);
Button remove = new Button(this);
prodName.setText(productDetails.getText());
unitPrice.setText(price.getText());
Quantity.setText(sellQuantity.getText());
total.setText("890");
remove.setBackgroundResource(R.drawable.delete);
prodName.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
prodName.setGravity(Gravity.CENTER);
unitPrice.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
unitPrice.setGravity(Gravity.CENTER);
Quantity.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
Quantity.setGravity(Gravity.CENTER);
remove.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
remove.setPadding(1,1,1,1);
/* Add Button to row. */
tr.addView(prodName);
tr.addView(unitPrice);
tr.addView(Quantity);
tr.addView(remove);
/* Add row to TableLayout. */
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));