for (int i = 0; i < rows; i++) {
TableRow row =new TableRow(this);
View v = new ImageView(getBaseContext());
TextView tv_main =new TextView(this);
ImageView iv = new imageView(this);
tv_main.setText("Test");
iv.setImageDrawable(v.getResources().getDrawable(R.drawable.home_icon));
row.addView(iv);
row.addView(tv_main);
table_layout.addView(row);
}
如何以編程方式設置高度和寬度?我曾試過以編程方式設置Imageview高度和寬度
iv.getLayoutParams().height=80;
iv.getLayoutParams().width=100;
但圖像不顯示。
嘗試http://stackoverflow.com/questions/4665853/how-to-populate-the-tablelayout-with-imageview-dynamically-in-android-jdk – 2015-02-11 12:21:07