标签:
1 package com.wangyi.tools; 2 3 import android.app.Activity; 4 import android.util.DisplayMetrics; 5 6 public class DisplayUtils { 7 8 private static DisplayUtils instance; 9 private Activity mActivity; 10 private DisplayUtils(Activity mActivity){ 11 this.mActivity=mActivity; 12 } 13 public static DisplayUtils getInstance(Activity mActivity){ 14 if(instance==null){ 15 instance=new DisplayUtils(mActivity); 16 } 17 return instance; 18 } 19 public final int[] getScreenSize(){ 20 int[] size=new int[2]; 21 DisplayMetrics dm = new DisplayMetrics(); 22 mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); 23 size[0]=dm.widthPixels; 24 size[1]=dm.heightPixels; 25 return size; 26 } 27 public final static int getWindowWidth(Activity mActivity) { 28 DisplayMetrics dm = new DisplayMetrics(); 29 mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); 30 return dm.widthPixels; 31 } 32 33 public final static int getWindowHeight(Activity mActivity) { 34 DisplayMetrics dm = new DisplayMetrics(); 35 mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm); 36 return dm.heightPixels; 37 } 38 }
标签:
原文地址:http://www.cnblogs.com/joyblabla/p/4649209.html