Android工具類之螢幕處理

2021-09-24 03:59:40 字數 1903 閱讀 2494

public class screenutil 

/**將dip或dp值轉換為px值,保證尺寸大小不變*/

public static int dip2px(context context, float dipvalue)

/**將px值轉換為sp值,保證文字大小不變*/

public static int px2sp(context context, float pxvalue)

/**將sp值轉換為px值,保證文字大小不變*/

public static int sp2px(context context, float spvalue)

/**螢幕寬度(畫素)*/

public static int getwindowwidth(activity context)

/**螢幕高度(畫素)*/

public static int getwindowheight(activity context)

/*** 獲得狀態列的高度

** @param context

* @return 狀態列高度

*/public static int getstatusheight(context context) catch (exception e)

return statusheight;

}/**

* 螢幕解析度

** @param mcontext

* @return 螢幕解析度資訊

*/public static screeninfo getscreeninfo(context mcontext) catch (exception ignored)

}// includes window decorations (statusbar bar/menu bar)

if (build.version.sdk_int >= build.version_codes.jelly_bean_mr1) catch (exception ignored)

}result.widthpixels = widthpixels;

result.heightpixels = heightpixels;

result.screenrealmetrics = widthpixels + "x" + heightpixels;

result.density = metrics.density;

result.density_default = displaymetrics.density_default;

result.densitydpi = metrics.densitydpi;

result.densitydpistr = metrics.densitydpi + " dpi";

result.scaleddensity = metrics.scaleddensity;

result.xdpi = metrics.xdpi;

result.ydpi = metrics.ydpi;

result.size = (math.sqrt(math.pow(widthpixels, 2) + math.pow(heightpixels, 2)) / metrics.densitydpi);

result.sizestr = string.format("%.2f", result.size);

return result;

}public static listgetgpufreqvolt()

br.close();

} catch (ioexception e)

return result;

}/**

* 螢幕資訊物件

*/public static class screeninfo ';}}

}

Android工具類 獲取螢幕資訊類

獲取螢幕的寬高,狀態列高度,截圖等 package com.duanlian import android.content.context import android.graphics.bitmap import android.graphics.rect import android.util....

Android獲取螢幕資料的工具類

直接上 package com.example import android.content.context import android.graphics.bitmap import android.graphics.rect import android.util.displaymetrics ...

螢幕工具類

獲得螢幕相關的輔助類 public class screenutils private screenutils cannot be instantiated throw new unsupportedoperationexception cannot be instantiated 獲得螢幕高度 p...