动态添加LinearLayout的高度实例
程序员文章站
2023-01-05 21:29:14
实例如下:
windowmanager wm = (windowmanager) getcontext()
.getsystemservice(...
实例如下:
windowmanager wm = (windowmanager) getcontext() .getsystemservice(context.window_service); int width = wm.getdefaultdisplay().getwidth(); int height = (int) (width - 22*density) / 3; linearlayout.layoutparams lp = (linearlayout.layoutparams) mlinearlayouttrafficcontrol.getlayoutparams(); lp.height = height; linearlayout.layoutparams lp2 = (linearlayout.layoutparams) mlinearlayouttrafficcontrol2.getlayoutparams(); lp2.height = height; linearlayout.layoutparams lp3 = (linearlayout.layoutparams) mlinearlayouttrafficservicesbusinessonline.getlayoutparams(); lp3.height = height;
注解:先获取屏幕宽度,通过屏幕宽度获取布局的高度。
density:是默认密度 private float density = 1.5f;
以上这篇动态添加linearlayout的高度实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。