如何更改现有布局参数的宽度和高度 [英] How to change width and height of existing layout params

查看:71
本文介绍了如何更改现有布局参数的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑RelativeLayout内的ImageView,它具有RelativeLayout的一些特定布局参数.我需要根据屏幕尺寸以编程方式更改ImageView的宽度和高度.

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));

我该如何实现?

推荐答案

使用getLayoutParams获取当前的布局参数.更改宽度和高度,然后从那里开始.如果该视图已经可见,则调用requestLayout强制进行新的布局传递.

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.

这篇关于如何更改现有布局参数的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆