Reputation: 13
I already try many ways but it seems doesn't work with me.
my code :
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);
Why it doesn't appear at all? but when I omitted setLayoutParams it appear as default size. Thanks for your help
Upvotes: 0
Views: 5148
Reputation: 669
To set ImageView width programmatically do this:
view.getLayoutParams().width = 20;
Upvotes: 1
Reputation: 166
Try this:
view.setLayoutParams(new TableRow.LayoutParams(20,30));
Upvotes: 4