i have an imagebutton and its width and height are specifiedin xml file.but i want to change
this with screen size of devices.
How can I set an ImageButton's width,height and margin programmatically?
Hi friend you can either set by this below code
btnPlayVideo.getLayoutParams().height = XX;
btnPlayVideo.getLayoutParams().width = XX;
or see this imageButton resize
//ImageView Setup
ImageView imageView = new ImageView(this);
//setting height and width of imageview
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//setting margins around imageimageview
params.setMargins(10, 10, 10, 10); //left, top, right, bottom
//adding attributes to the imageview
imageView.setLayoutParams(params);
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