How to change width and height of existing layout params

天大地大妈咪最大 提交于 2019-12-24 16:11:04

问题


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:


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.



来源:https://stackoverflow.com/questions/35326892/how-to-change-width-and-height-of-existing-layout-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!