实例如下:
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的高度实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。