我在android中動態創建錶行並在該行創建按鈕。所有的渲染都很好,但創建的按鈕填充父項,即佔用父行的全部寬度。我希望它是一個固定寬度的數組,即150px。動態創建的按鈕不填充父項
我的代碼
TableRow rows = new TableRow(this);
TableLayout.LayoutParams tableRowParamss=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
rows.setBackgroundColor(Color.parseColor("#62b0ff"));
tableRowParamss.setMargins(0, 0, 0, 40);
rows.setLayoutParams(tableRowParamss);
Button ib = new Button(this);
//ib.setBackgroundResource(R.drawable.accept);
final float scale = getResources().getDisplayMetrics().density;
int heightDp = (int) (33 * scale + 0.5f);
int widthDp = (int) (60 * scale + 0.5f);
ViewGroup.LayoutParams bLp = new ViewGroup.LayoutParams(widthDp,heightDp);
rows.addView(ib);
table.addView(rows);
我怎樣才能使按鈕的寬度固定爲150px和對齊排的右側?
設置按鈕的佈局PARAMS具有150 – 2013-05-09 12:00:24