動態添加LinearLayout的高度


   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;

    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM