android获取屏幕相关信息

阅读更多
public class TestActivity entends Activity{
    private static final String DEBUT_TAG = "testActivity";
    @Override
     protected void onCreate(Bundle savedInstanceState) {
        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)
        Log.d(DEBUT_TAG, "width="+width+",height="+height+",density="+density+",densityDpi="+densityDpi);
     }
}

        

 

你可能感兴趣的:(android,屏幕)