android - Resizing an ImageView within a TableLayout programmatically -
if have tablelayout structure (below) defines 2 imageviews. 1 specifies pixel values width/height. works expect - pic 1 resized 50px , pic2 kept @ original size:
<tablelayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <tablerow> <imageview android:src="@drawable/pic1" android:layout_width="50px" android:layout_height="50px" /> <imageview android:src="@drawable/pic2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </tablerow> </tablelayout>
but need above programmatically this...
tablelayout tablelayout = new tablelayout(ctx); tablerow tablerow = new talerow(ctx); imageview imageviewone = new imageview(ctx); imageview imageviewtwo = new imageview(ctx); imageviewone.setimageresource(r.drawable.pic1); imageviewtwo.setimageresource(r.drawable.pic2); imageviewone.setlayoutparams(new layoutparams(50, 50)); rootview.addview(tablelayout); tablelayout.addview(tablerow); tablerow.addview(imageviewone); tablerow.addview(imageviewtwo);
the above doesn't same xml - first imageview not show @ using programmatic way after adding setlayoutparams() method it.
i mist missing here, is different?
thanks!
ok i've managed solve this. instead of using:
imageviewone.setlayoutparams(new layoutparams(50, 50));
i used instead:
imageviewone.setlayoutparams(new tablerow.layoutparams(50, 50));
Comments
Post a Comment