/**
* app内可用的分辨率
* @param ctx
* @return
*/
public static int getScreenH(Context ctx) {
WeakReference<Context> weakReference = new WeakReference<>(ctx);
DisplayMetrics displayMetrics = null;
displayMetrics = weakReference.get().getResources().getDisplayMetrics();
return displayMetrics.heightPixels;
}
/**
* 真实的硬件分辨率
* @param context
* @return
*/
public static int getRawScreenH(Context context) {
int width = 0, height = 0;
final DisplayMetrics metrics = new DisplayMetrics();
Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
// For JellyBean 4.2 (API 17) and onward
display.getRealMetrics(metrics);
width = metrics.widthPixels;
height = metrics.heightPixels;
return height;
}
网友评论