动态添加LinearLayout的高度实例
实例如下:
WindowManagerwm=(WindowManager)getContext() .getSystemService(Context.WINDOW_SERVICE); intwidth=wm.getDefaultDisplay().getWidth(); intheight=(int)(width-22*density)/3; LinearLayout.LayoutParamslp=(LinearLayout.LayoutParams)mLinearLayoutTrafficControl.getLayoutParams(); lp.height=height; LinearLayout.LayoutParamslp2=(LinearLayout.LayoutParams)mLinearLayoutTrafficControl2.getLayoutParams(); lp2.height=height; LinearLayout.LayoutParamslp3=(LinearLayout.LayoutParams)mLinearLayoutTrafficServicesBusinessOnline.getLayoutParams(); lp3.height=height;
注解:先获取屏幕宽度,通过屏幕宽度获取布局的高度。
density:是默认密度privatefloatdensity=1.5f;
以上这篇动态添加LinearLayout的高度实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。