zoukankan      html  css  js  c++  java
  • android获得屏幕高度和宽度

    获取屏幕的宽度与高度有以下几种方法:
    1、WindowManager wm = (WindowManager) getContext()
                        .getSystemService(Context.WINDOW_SERVICE);
     
         int width = wm.getDefaultDisplay().getWidth();
         int height = wm.getDefaultDisplay().getHeight();
     
    2、WindowManager wm = this.getWindowManager();
     
         int width = wm.getDefaultDisplay().getWidth();
         int height = wm.getDefaultDisplay().getHeight();
     
    3、 DisplayMetrics metric = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metric);
            int width = metric.widthPixels;     // 屏幕宽度(像素)
            int height = metric.heightPixels;   // 屏幕高度(像素)
            float density = metric.density;      // 屏幕密度(0.75 / 1.0 / 1.5)
            int densityDpi = metric.densityDpi;  // 屏幕密度DPI(120 / 160 / 240)
  • 相关阅读:
    接口分类
    HTTPS和HTTP的主要区别
    协议类
    小程序
    Polyfill
    去重数组
    odoo 接口跨域请求报错
    docker-compose 自定义容器名称
    linux ssh 防暴力破解fail2ban
    odoo 知识点
  • 原文地址:https://www.cnblogs.com/exmyth/p/4727545.html
Copyright © 2011-2022 走看看