1. 程式人生 > >獲取屏幕尺寸,大於7為平板,小於7為手機

獲取屏幕尺寸,大於7為平板,小於7為手機

nag man private thp eight pre xdp ble gets

/**
* 獲取屏幕物理尺寸
* @return
*/
private double getScreenSize(){
DisplayMetrics dm = new DisplayMetrics();
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi, 2);
double y = Math.pow(dm.heightPixels/dm.ydpi, 2);
double screenInches = Math.sqrt(x+y);

return screenInches;
}



獲取屏幕尺寸,大於7為平板,小於7為手機