Skip to content

Commit 0fa530d

Browse files
feer921Lyphy999
authored andcommitted
ScreenUtils 增加 getDisplayMetricsDesc()方法
1 parent f141ddf commit 0fa530d

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/common/base/utils/ScreenUtils.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class ScreenUtils {
3434
private static int windowHeight;
3535
private static float density;
3636
private static int statusBarHeight = 10;
37+
38+
private static DisplayMetrics displayMetrics;
3739
/**
3840
* 手机的导航栏(虚拟)
3941
* 横屏时:为宽
@@ -52,7 +54,7 @@ public static void init(Context context) {
5254
if (windowManager == null) {
5355
return;
5456
}
55-
DisplayMetrics displayMetrics = new DisplayMetrics();
57+
displayMetrics = new DisplayMetrics();
5658
Display defDisplay = windowManager.getDefaultDisplay();
5759
if (defDisplay == null) {
5860
return;
@@ -311,6 +313,24 @@ public static String getDevInfos() {
311313
return " windowWidth:" + windowWidth + " windowHeight:" + windowHeight + " density:" + density;
312314
}
313315

316+
public static String getDisplayMetricsDesc() {
317+
DisplayMetrics curDisplayMetrics = null;
318+
Resources res = null;
319+
int swdp = 0;
320+
if (sContext != null) {
321+
res = sContext.getResources();
322+
}
323+
if (res != null) {
324+
curDisplayMetrics = res.getDisplayMetrics();
325+
swdp = res.getConfiguration().smallestScreenWidthDp;
326+
}
327+
StringBuilder sb = new StringBuilder();
328+
sb.append("当前显示信息:").append(curDisplayMetrics)
329+
.append(" --> 实际显示信息:").append(displayMetrics)
330+
.append(" 最短宽 dpi:").append(swdp)
331+
;
332+
return sb.toString();
333+
}
314334
public static int[] getCurScreenWidthHeight(Context context) {
315335
int resultWidth = 0;
316336
int resultHeight = 0;

0 commit comments

Comments
 (0)