Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adjust image button's margin,height and width programatically

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?

like image 538
azhar Avatar asked Feb 14 '14 19:02

azhar


2 Answers

Hi friend you can either set by this below code

btnPlayVideo.getLayoutParams().height = XX;
btnPlayVideo.getLayoutParams().width = XX;

or see this imageButton resize

like image 68
Android Leo Avatar answered Nov 14 '22 09:11

Android Leo


//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);
like image 21
Hamid Shatu Avatar answered Nov 14 '22 09:11

Hamid Shatu