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);
}
How to set height and width programmatically? I had tried
iv.getLayoutParams().height=80;
iv.getLayoutParams().width=100;
but image is not display.
You need to create a new LayoutParams object and set the height and width for it and then pass it to the iv.setLayoutParams() method.
TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(100, 80);
iv.setLayoutParams(layoutParams);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With