How to change width and height of existing layout params

1.4k Views Asked by At

Please consider ImageView inside RelativeLayout it has some specific layout params for RelativeLayout. I need to change the width and height of my ImageView programatically according to the screen size.

How can I save all layout parameters but only change width and height

Following code creates empty layout params but I need to save my old params and change only height and width.

   imageViewArticleImage.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mScreenSize.y / 3));

How can I achieve this ?

1

There are 1 best solutions below

5
Gabe Sechan On BEST ANSWER

Use getLayoutParams to get the current layout params. Change the width and height and go from there. IF the view is already visible, call requestLayout to force a new layout pass.