zoukankan      html  css  js  c++  java
  • Android 获取屏幕大小和密度

    Android 获取屏幕大小和密度

    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)


    在project的AndroidManifest.xml文件里。增加supports-screens节点。详细的内容例如以下:
            <supports-screens
                android:smallScreens="true"
                android:normalScreens="true"
                android:largeScreens="true"
                android:resizeable="true"
                android:anyDensity="true"/>

    这样当前的Android该方案支持多种分辨率,然后,我们可以得到的正确的物理尺寸。

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    hdu 4015找规律
    hdu4473
    hdu 4016搜索
    hdu4465精度控制
    hdu 2965组合数学题
    hdu 4022map和list等数据结构的应用
    hdu4464超级大水题
    在ASP.NET中实现Url Rewriting
    DotText源码阅读(1)调试
    DotText源码阅读(2)数据库表结构
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4888060.html
Copyright © 2011-2022 走看看