0
我已經嘗試了很多方法,但它似乎不適用於我。以編程方式設置寬度Imageview
我的代碼: TableLayout tTopic=(TableLayout) findViewById(R.id.__topic);
TableRow tr = new TableRow(this);
TableLayout.LayoutParams lpt2=null;
lpt2 = new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
lpt2.setMargins(4, 2, 4, 2);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
ImageView view = new ImageView(this);
view.setLayoutParams(new LayoutParams(20,30));
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
view.setImageResource(R.drawable.kotak);
tr.addView(view);
tTopic.addView(tr,lpt2);
爲什麼它沒有出現?但是當我省略setLayoutParams時,它顯示爲默認大小。感謝您的幫助
使用'TableRow.LayoutParams' –