支付宝赞助帐号:service@kuitao8.com 

android计算器LinearLayouty高度的办法

Created2018-06-21   Views 646    Author 懒人程序
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;         // 屏幕宽度(像素)
        int height = dm.heightPixels;       // 屏幕高度(像素)
        float density = dm.density;         // 屏幕密度(0.75 / 1.0 / 1.5)
        int densityDpi = dm.densityDpi;     // 屏幕密度dpi(120 / 160 / 240)
        // 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
        int screenWidth = (int) (width / density) ;  // 屏幕宽度(dp)
        int screenHeight = (int) (height / density) - 110 ;// 屏幕高度(dp)
       // Toast.makeText(WebViewActivity.this, "1111-> " + screenHeight, Toast.LENGTH_SHORT).show();
        int heights =(int) (height - 115*density);
        int widths = dm.widthPixels;
        Resources ra=getResources();
        float btn_h =ra.getDimension(R.dimen.auto_heihgt)/density;
       // Toast.makeText(WebViewActivity.this, "22-> " + btn_h, Toast.LENGTH_SHORT).show();
        LinearLayout ss = (LinearLayout) findViewById(R.id.web_view_design);
        ss.setLayoutParams(new LinearLayout.LayoutParams(widths, heights));
上一篇: weex 获取接口数据的方法
下一篇: android webview加header的方法
支持键盘 ← →

邮件订阅

订阅我们的精彩内容