平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

1、设备屏幕参数获取、计算、几个设备相关参数

计算示范:某手机 6.39英寸 (对角线),1英寸是160dp,所以是 1022.4dp,分辨率 2340 x 1080,,勾股定理得到对角线长为2577.2 ,所以屏幕密度比是2577.2  / 6.39 = 2.52。

打印DisplayMetics 与 Configuration如下

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

常见的几种获取方式 

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

一种获取状态栏的方式

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

一种获取导航栏的方式

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

-------------------------竖屏-----------------------

vivo x27

2021-01-05 19:50:35.753 32273-32273/com.example.adaptersize D/----->: displayMetrics1 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 19:50:35.753 32273-32273/com.example.adaptersize D/----->: configuration1 screenWidthDp = 360,screenHeightDp = 752,densityDpi = 480
2021-01-05 19:50:35.753 32273-32273/com.example.adaptersize D/----->: displayMetrics2 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 19:50:35.753 32273-32273/com.example.adaptersize D/----->: configuration2 screenWidthDp = 360,screenHeightDp = 752,densityDpi = 480
2021-01-05 19:50:35.754 32273-32273/com.example.adaptersize D/----->: displayMetrics3 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 19:50:35.755 32273-32273/com.example.adaptersize D/----->: displayMetrics4 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 19:50:35.755 32273-32273/com.example.adaptersize D/----->: StatusBarHeight = 84
2021-01-05 19:50:35.963 32273-32273/com.example.adaptersize D/----->: NavigationHeight 126,windowInsets.getSystemWindowInsetBottom = 0,isShowing = false

小米9

2021-01-05 20:12:10.721 31581-31581/com.example.adaptersize D/----->: displayMetrics1 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:12:10.721 31581-31581/com.example.adaptersize D/----->: configuration1 screenWidthDp = 392,screenHeightDp = 776,densityDpi = 440
2021-01-05 20:12:10.721 31581-31581/com.example.adaptersize D/----->: displayMetrics2 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:12:10.721 31581-31581/com.example.adaptersize D/----->: configuration2 screenWidthDp = 392,screenHeightDp = 776,densityDpi = 440
2021-01-05 20:12:10.722 31581-31581/com.example.adaptersize D/----->: displayMetrics3 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:12:10.722 31581-31581/com.example.adaptersize D/----->: displayMetrics4 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:12:10.722 31581-31581/com.example.adaptersize D/----->: StatusBarHeight = 75
2021-01-05 20:12:10.790 31581-31581/com.example.adaptersize D/----->: NavigationHeight 130,windowInsets.getSystemWindowInsetBottom = 0,isShowing = false

华为mate 20

2021-01-05 20:15:29.832 20649-20649/com.example.adaptersize D/----->: displayMetrics1 widthPixels = 1080,heightPixels = 2159,xdpi = 428.625,ydpi = 428.553,density = 3.0,densityDpi = 480,scaledDensity = 3.4499998
2021-01-05 20:15:29.832 20649-20649/com.example.adaptersize D/----->: configuration1 screenWidthDp = 360,screenHeightDp = 719,densityDpi = 480
2021-01-05 20:15:29.832 20649-20649/com.example.adaptersize D/----->: displayMetrics2 widthPixels = 1080,heightPixels = 2159,xdpi = 428.625,ydpi = 428.553,density = 3.0,densityDpi = 480,scaledDensity = 3.4499998
2021-01-05 20:15:29.833 20649-20649/com.example.adaptersize D/----->: configuration2 screenWidthDp = 360,screenHeightDp = 719,densityDpi = 480
2021-01-05 20:15:29.833 20649-20649/com.example.adaptersize D/----->: displayMetrics3 widthPixels = 1080,heightPixels = 2159,xdpi = 428.625,ydpi = 428.553,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 20:15:29.834 20649-20649/com.example.adaptersize D/----->: displayMetrics4 widthPixels = 1080,heightPixels = 2244,xdpi = 428.625,ydpi = 428.553,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-05 20:15:29.834 20649-20649/com.example.adaptersize D/----->: StatusBarHeight = 85
2021-01-05 20:15:30.001 20649-20649/com.example.adaptersize D/----->: NavigationHeight 128,windowInsets.getSystemWindowInsetBottom = 0,isShowing = false

小米8

2021-01-23 11:15:27.587 9644-9644/com.example.adaptersize I/----->: displayMetrics1 1005048000 widthPixels = 1080,heightPixels = 2115,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:15:27.587 9644-9644/com.example.adaptersize I/----->: displayMetrics2 1005048000 widthPixels = 1080,heightPixels = 2115,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:15:27.587 9644-9644/com.example.adaptersize I/----->: appDisplayMetrics 1005048000 widthPixels = 1080,heightPixels = 2115,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:15:27.588 9644-9644/com.example.adaptersize I/----->: displayMetrics3 1005048000 widthPixels = 1080,heightPixels = 2115,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:15:27.588 9644-9644/com.example.adaptersize I/----->: displayMetrics4 1068249600 widthPixels = 1080,heightPixels = 2248,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75

2021-01-23 11:15:27.610 9644-9644/com.example.adaptersize I/----->: StatusBarHeight = 89

2021-01-23 11:15:27.680 9644-9644/com.example.adaptersize I/----->: NavigationHeight 86,windowInsets.getSystemWindowInsetBottom = 44,isShowing = false

 

小米9开启虚拟导航栏模式:

2021-01-05 20:19:05.193 2100-2100/com.example.adaptersize D/----->: displayMetrics1 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:19:05.193 2100-2100/com.example.adaptersize D/----->: configuration1 screenWidthDp = 392,screenHeightDp = 776,densityDpi = 440
2021-01-05 20:19:05.193 2100-2100/com.example.adaptersize D/----->: displayMetrics2 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:19:05.193 2100-2100/com.example.adaptersize D/----->: configuration2 screenWidthDp = 392,screenHeightDp = 776,densityDpi = 440
2021-01-05 20:19:05.194 2100-2100/com.example.adaptersize D/----->: displayMetrics3 widthPixels = 1080,heightPixels = 2135,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:19:05.194 2100-2100/com.example.adaptersize D/----->: displayMetrics4 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-05 20:19:05.194 2100-2100/com.example.adaptersize D/----->: StatusBarHeight = 75
2021-01-05 20:19:05.265 2100-2100/com.example.adaptersize D/----->: NavigationHeight 130,windowInsets.getSystemWindowInsetBottom = 130,isShowing = true

 

小米8开启虚拟导航模式

2021-01-23 11:07:39.005 4150-4150/com.example.adaptersize I/----->: displayMetrics1 964180800 widthPixels = 1080,heightPixels = 2029,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:07:39.006 4150-4150/com.example.adaptersize I/----->: displayMetrics2 964180800 widthPixels = 1080,heightPixels = 2029,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:07:39.006 4150-4150/com.example.adaptersize I/----->: appDisplayMetrics 964180800 widthPixels = 1080,heightPixels = 2029,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:07:39.007 4150-4150/com.example.adaptersize I/----->: displayMetrics3 964180800 widthPixels = 1080,heightPixels = 2029,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-23 11:07:39.007 4150-4150/com.example.adaptersize I/----->: displayMetrics4 1068249600 widthPixels = 1080,heightPixels = 2248,xdpi = 403.411,ydpi = 402.107,density = 2.75,densityDpi = 440,scaledDensity = 2.75

2021-01-23 11:07:39.030 4150-4150/com.example.adaptersize I/----->: StatusBarHeight = 89

2021-01-23 11:07:39.098 4150-4150/com.example.adaptersize I/----->: NavigationHeight 255,windowInsets.getSystemWindowInsetBottom = 130,isShowing = false

-------------------------横屏-----------------------

小米9

2021-01-06 10:20:20.759 9574-9574/com.example.adaptersize D/----->: displayMetrics1 widthPixels = 2135,heightPixels = 1080,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-06 10:20:20.759 9574-9574/com.example.adaptersize D/----->: configuration1 screenWidthDp = 776,screenHeightDp = 365,densityDpi = 440
2021-01-06 10:20:20.759 9574-9574/com.example.adaptersize D/----->: displayMetrics2 widthPixels = 2135,heightPixels = 1080,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-06 10:20:20.759 9574-9574/com.example.adaptersize D/----->: configuration2 screenWidthDp = 776,screenHeightDp = 365,densityDpi = 440
2021-01-06 10:20:20.759 9574-9574/com.example.adaptersize D/----->: displayMetrics3 widthPixels = 2135,heightPixels = 1080,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-06 10:20:20.760 9574-9574/com.example.adaptersize D/----->: displayMetrics4 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 404.326,density = 2.75,densityDpi = 440,scaledDensity = 2.75
2021-01-06 10:20:20.760 9574-9574/com.example.adaptersize D/----->: StatusBarHeight = 75
2021-01-06 10:20:20.768 9574-9574/com.example.adaptersize D/----->: NavigationHeight 130,windowInsets.getSystemWindowInsetBottom = 0,isShowing = false

 

  设备分辨率 真实像数密度dpi 真实屏幕密度比density 设备像数密度dpi 设备屏幕密度比density 状态栏(px) 底部导航栏(px)
荣耀平板5 1200 x 1920 225.777 1.4111 320 2 48 68
华为matepad 1600 x 2560 280.275 1.752 400 2.5 79 84
小米9 1080 x 2340 403.411 2.52 440 2.75 75 130
小米8 1080 x 2248 403.411 2.52 440 2.75 89 130
步步高S1W 768 x 1024 159.895 1 160 1 25 40
vivo x27 1080 x 2340 403.411 2.52 480 3 84 126
华为mate20 1080 x 2244 428.625 2.68 480 3 85 128

以上数据表明:

1、设备密度比不完全是真实的屏幕密度比,各机型都有出入。平板设备与真实屏幕密度差异比手机大得多,所以pad自带放大效果。

2、横竖屏获取的宽高相反,另外由于导航栏的差异 导致获取的高并不准确。

3、xdpi 和 ydpi是真实的屏幕密度比,两者相同代表屏幕两个维度上密度均匀

ps:可以利用此 界定 超过7.5英寸的设备 是平板:

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

2、AndroidAutoSize概述

目标适配效果:以宽或者高一个维度去保持 某长度 在设计图上的占比与 实际显示在设备上的占比 一致。

具体描述:宽维度为例:设计图宽是360dp,那么一个控件设计图上宽100dp,那么无论在任何手机屏幕上该控件都占屏幕的100/360,所以 本质就是  以屏幕宽度 / 设计图宽  作为新的px dp 转换关系 ,替换系统dp px原有转换关系。

如何变更系统的屏幕密度比:系统dp转换的场景,如XML,基本都是通过 DisplayMetrics 来计算的 :

例如:xml加载 走到 ViewGroup generateLayoutParams

 平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

几个变量:

  • DisplayMetrics#density 就是上述的density

  • DisplayMetrics#densityDpi 就是上述的dpi

  • DisplayMetrics#scaledDensity 字体的缩放因子,正常情况下和density相等,但是调节系统字体大小后会改变这个值

所以只要变更这几个变量值就可以实现适配目标。

 

一般理解:

每个activity可以获取 DisplayMetrics 、Configuration    activity.getResources().getDisplayMetrics ( )              activity.getResources().getConfiguration() 
Application可以获取  DisplayMetrics  、Configuration       Application().getResources().getDisplayMetrics ( )    getApplication().getResources().getConfiguration()

Configuration里的   screenWidthDp  screenHeightDp也被系统使用,需要同步修改

对于字体sp则同步缩放,比如字体设置不是标准,大字体放大了2倍,autoSize对于dp缩放倍数是1.5则 字体最后 相对于原有dp放大 了 两者的乘积3倍。

只能以一边维度进行适配,另外一边则按次维度 缩放 遵照常规布局规则。

 

3、AndroidAutoSize 核心逻辑代码:

注册provide提前初始化

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

初始化 重点 ui设计值 、宽高维度基准、记存原始屏幕参数

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

设置activity生命周期回调

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

回调监听里面用WrapperAutoAdaptStrategy代理默认的DefaultAutoAdaptStrategy适配策略适配,可以看到适配前后的时机都对外进行了暴露,此处回调可以做一些自定义操作

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

默认适配规则处理了 外部三方库的适配兼容、CancelAdapt 取消适配、CustomAdapt自定义适配 

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

CustomAdapt将使用中自定义的设计图尺寸就行适配

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

在onCreate、onStart里面执行了适配,并且支持了对 Fragment的适配支持

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

Fragment在onCreate执行了一次适配

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

开始适配

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

跟进适配维度与UI设计图值执行最终的autoConvertDensity方法

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

核心计算

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

targetDensity 即前面所说的 以屏幕宽度 / 设计图宽  作为新的dp px转换关系,重新计算Density Dpi ScaledDensity等值后 修正activity、application的DisplayMetrics与Configuration

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

至此,AndroidAutoSize 适配结束。

 

简而言之,AndroidAuSize利用对生命周期监听修改DisplayMetrics的参数进行页面缩放,实现横或竖一个维度上  某长度值在 任一手机屏幕上显示效果与 在设计图上 占比相等。

 

值得注意的是,初始化中增加了

1、对字体大小设置变更的监听处理

2、横竖屏切换会导致宽高互换,即AndroidAutoSize 设计原意是 横屏状态下的页面 也要参照横屏的设计图 ,默认用宽维度来进行适配

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

4、是否靠谱?测试验证

验证displayMetrics参数的修改;验证横竖屏切换生命周期 ;验证XML、动态加载两种 ;

测试机器 vivo X27,View 100dp x 100dp ,xml静态添加绿色的View,onResume之后post 执行 动态添加红色的View

XMLLandScapeActivity是清单文件指定横屏的activity,CodeLandScapeActivity是在onCreate之后动态设置横屏的activity,手机开启屏幕旋转。

关闭AndroidAutoSize适配

打开 MainActivity

2021-01-28 16:23:13.167 D/----->: *****Application onActivityCreated MainActivity 131104389 前*****
2021-01-28 16:23:13.167 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.167 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.167 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.168 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 122550932 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.169 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 17103165 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.175 D/----->: *****Application onActivityCreated MainActivity 131104389 后*****
2021-01-28 16:23:13.175 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.175 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.175 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.176 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 87876914 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.176 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 258933379 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.178 D/----->: MainActivity 131104389 onCreate
2021-01-28 16:23:13.178 I/----->: StatusBarHeight = 84
2021-01-28 16:23:13.235 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 16:23:13.235 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.235 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.235 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.236 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 231794534 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.236 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 123194023 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.237 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 16:23:13.237 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.237 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.237 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.238 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 71981908 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.238 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 41200381 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:13.239 D/----->: MainActivity 131104389 onStart
2021-01-28 16:23:13.241 D/----->: MainActivity 131104389 onResume
2021-01-28 16:23:13.277 I/----->: NavigationHeight 126,windowInsets.getSystemWindowInsetBottom = 126,isShowing = true
2021-01-28 16:23:13.345 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:23:13.349 I/----->: View width = 300,height = 300
2021-01-28 16:23:13.362 I/----->: View width = 300,height = 300

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

再打开一个Main2Activity

2021-01-28 16:23:32.627 D/----->: MainActivity 131104389 onPause
2021-01-28 16:23:32.664 D/----->: *****Application onActivityCreated Main2Activity 44240648 前*****
2021-01-28 16:23:32.664 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.664 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.664 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.665 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 171944071 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.665 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 31331252 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.666 D/----->: *****Application onActivityCreated Main2Activity 44240648 后*****
2021-01-28 16:23:32.666 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.666 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.666 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.667 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 113732573 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.667 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 263484242 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.668 D/----->: Main2Activity 44240648 onCreate
2021-01-28 16:23:32.669 I/----->: StatusBarHeight = 84
2021-01-28 16:23:32.710 D/----->: *****Application onActivityStarted Main2Activity 44240648 前*****
2021-01-28 16:23:32.710 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.710 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.710 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.711 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 62408064 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.711 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 195217337 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.712 D/----->: *****Application onActivityStarted Main2Activity 44240648 后*****
2021-01-28 16:23:32.712 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.712 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.712 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.713 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 255825918 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.713 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 181881695 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:32.714 D/----->: Main2Activity 44240648 onStart
2021-01-28 16:23:32.715 D/----->: Main2Activity 44240648 onResume
2021-01-28 16:23:32.731 I/----->: NavigationHeight 126,windowInsets.getSystemWindowInsetBottom = 126,isShowing = true
2021-01-28 16:23:32.774 D/----->: Main2Activity 44240648 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:23:32.778 I/----->: View width = 300,height = 300
2021-01-28 16:23:32.787 I/----->: View width = 300,height = 300
2021-01-28 16:23:33.132 D/----->: MainActivity 131104389 onStop

Application注册的Activity生命周期回调监听在activity生命周期执行执行;

Activity和Application的displayMetrics对象不同,Activity之间貌似共用同一个displayMetrics;

回退到MainActivity 打开XMLLandScapeActivity

2021-01-28 16:23:53.491 D/----->: MainActivity 131104389 onPause
2021-01-28 16:23:53.617 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 16:23:53.617 I/----->: displayMetrics context.getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.618 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.618 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.622 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 9256247 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.626 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 72614564 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.660 D/----->: *****Application onActivityCreated XMLLandScapeActivity 194074633 前*****
2021-01-28 16:23:53.660 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.660 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.660 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.661 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 65956805 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.661 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 12065050 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.662 D/----->: *****Application onActivityCreated XMLLandScapeActivity 194074633 后*****
2021-01-28 16:23:53.662 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.662 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.662 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.663 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 170183755 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.663 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 82576936 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.664 D/----->: XMLLandScapeActivity 194074633 onCreate
2021-01-28 16:23:53.736 D/----->: *****Application onActivityStarted XMLLandScapeActivity 194074633 前*****
2021-01-28 16:23:53.736 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.737 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.737 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.740 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 37833048 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.740 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 204815025 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.740 D/----->: *****Application onActivityStarted XMLLandScapeActivity 194074633 后*****
2021-01-28 16:23:53.741 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.741 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.741 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.741 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 7478166 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.742 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 16884503 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:23:53.743 D/----->: XMLLandScapeActivity 194074633 onStart
2021-01-28 16:23:53.744 D/----->: XMLLandScapeActivity 194074633 onResume
2021-01-28 16:23:53.834 D/----->: MainActivity 131104389 onStop
2021-01-28 16:23:53.853 D/----->: XMLLandScapeActivity 194074633 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:23:53.857 I/----->: View width = 300,height = 300
2021-01-28 16:23:53.881 I/----->: View width = 300,height = 300

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

xml预先设置方向的情况下 Application onConfigurationChanged 执行在onCreate监听之前

再打开一个XMLLandScapeActivity

2021-01-28 16:24:09.529 D/----->: XMLLandScapeActivity 194074633 onPause
2021-01-28 16:24:09.553 D/----->: *****Application onActivityCreated XMLLandScapeActivity 180060167 前*****
2021-01-28 16:24:09.554 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.554 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.554 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.554 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 50712786 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.555 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 59119011 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.555 D/----->: *****Application onActivityCreated XMLLandScapeActivity 180060167 后*****
2021-01-28 16:24:09.555 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.555 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.556 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.556 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 163647648 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.557 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 100992089 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.557 D/----->: XMLLandScapeActivity 180060167 onCreate
2021-01-28 16:24:09.578 D/----->: *****Application onActivityStarted XMLLandScapeActivity 180060167 前*****
2021-01-28 16:24:09.579 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.579 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.579 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.579 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 180359810 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.580 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 200781203 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.580 D/----->: *****Application onActivityStarted XMLLandScapeActivity 180060167 后*****
2021-01-28 16:24:09.580 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.580 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.580 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.581 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 34202064 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.581 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 132298185 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:09.581 D/----->: XMLLandScapeActivity 180060167 onStart
2021-01-28 16:24:09.582 D/----->: XMLLandScapeActivity 180060167 onResume
2021-01-28 16:24:09.658 D/----->: XMLLandScapeActivity 180060167 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:24:09.663 I/----->: View width = 300,height = 300
2021-01-28 16:24:09.684 I/----->: View width = 300,height = 300
2021-01-28 16:24:10.018 D/----->: XMLLandScapeActivity 194074633 onStop

横屏、竖屏Activity之间displayMetrics的对象是不一样的

返回到第一个XMLLandScapeActivity

2021-01-28 16:24:28.216 D/----->: XMLLandScapeActivity 180060167 onPause
2021-01-28 16:24:28.248 D/----->: XMLLandScapeActivity 194074633 onRestart
2021-01-28 16:24:28.250 D/----->: *****Application onActivityStarted XMLLandScapeActivity 194074633 前*****
2021-01-28 16:24:28.251 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.251 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.252 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.255 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 8478464 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.256 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 201827129 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.257 D/----->: *****Application onActivityStarted XMLLandScapeActivity 194074633 后*****
2021-01-28 16:24:28.258 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.258 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.258 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.265 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 168955262 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.267 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 121656031 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:28.267 D/----->: XMLLandScapeActivity 194074633 onStart
2021-01-28 16:24:28.270 D/----->: XMLLandScapeActivity 194074633 onResume
2021-01-28 16:24:28.330 I/----->: View width = 300,height = 300
2021-01-28 16:24:28.330 D/----->: XMLLandScapeActivity 194074633 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:24:28.365 I/----->: View width = 300,height = 300
2021-01-28 16:24:28.678 D/----->: XMLLandScapeActivity 180060167 onStop
2021-01-28 16:24:28.680 D/----->: XMLLandScapeActivity 180060167 onDestroy
返回到MainActivity

2021-01-28 16:24:48.152 D/----->: XMLLandScapeActivity 194074633 onPause
2021-01-28 16:24:48.280 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 360,screenHeightDp = 710***** 注意后续打印的context是Application
2021-01-28 16:24:48.280 I/----->: displayMetrics context.getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.281 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.281 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.282 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 116617587 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.283 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 69896240 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.285 D/----->: MainActivity 131104389 onRestart
2021-01-28 16:24:48.286 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 16:24:48.286 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.286 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.286 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.287 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 12242089 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.288 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 228250158 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.288 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 16:24:48.288 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.288 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.288 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.289 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 76132815 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.291 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 132642652 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:24:48.292 D/----->: MainActivity 131104389 onStart
2021-01-28 16:24:48.294 D/----->: MainActivity 131104389 onResume
2021-01-28 16:24:48.367 I/----->: View width = 300,height = 300
2021-01-28 16:24:48.367 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:24:48.426 I/----->: View width = 300,height = 300
2021-01-28 16:24:48.486 D/----->: XMLLandScapeActivity 194074633 onStop
2021-01-28 16:24:48.487 D/----->: XMLLandScapeActivity 194074633 onDestroy

打开CodeLandScapeActivity

2021-01-28 16:25:12.683 D/----->: MainActivity 131104389 onPause
2021-01-28 16:25:12.834 D/----->: *****Application onActivityCreated CodeLandScapeActivity 12585809 前*****
2021-01-28 16:25:12.834 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.834 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.834 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.835 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 229155876 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.837 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 178850701 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.837 D/----->: *****Application onActivityCreated CodeLandScapeActivity 12585809 后*****
2021-01-28 16:25:12.837 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.837 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.837 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.837 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 126685506 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.838 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 224306515 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.839 D/----->: CodeLandScapeActivity 12585809 onCreate
2021-01-28 16:25:12.940 D/----->: *****Application onActivityStarted CodeLandScapeActivity 12585809 前*****
2021-01-28 16:25:12.940 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.940 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.940 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.941 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 210722388 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.941 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 12644861 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.942 D/----->: *****Application onActivityStarted CodeLandScapeActivity 12585809 后*****
2021-01-28 16:25:12.942 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.942 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.942 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.943 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 43011826 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.943 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 11241795 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:12.943 D/----->: CodeLandScapeActivity 12585809 onStart
2021-01-28 16:25:12.944 D/----->: CodeLandScapeActivity 12585809 onResume
2021-01-28 16:25:13.016 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 16:25:13.016 I/----->: displayMetrics context.getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.016 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.016 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.017 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 191285834 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.017 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 195222971 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.020 D/----->: CodeLandScapeActivity 12585809 Activity onConfigurationChanged
2021-01-28 16:25:13.020 I/----->: displayMetrics context.getResources() displayMetrics 227119832 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.020 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.020 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.021 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 157386289 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.022 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 5194006 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:13.038 D/----->: CodeLandScapeActivity 12585809 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:25:13.043 I/----->: View width = 300,height = 300
2021-01-28 16:25:13.061 I/----->: View width = 300,height = 300
2021-01-28 16:25:13.084 D/----->: MainActivity 131104389 onStop

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

注意到一开始是竖屏的displayMetrics,并且onConfigurationChanged发生在onResume之后,且displayMetrics对象也不是预想的横屏公共的

再打开一个CodeLandScapeActivity

 2021-01-28 16:25:26.456 D/----->: CodeLandScapeActivity 12585809 onPause
2021-01-28 16:25:26.488 D/----->: *****Application onActivityCreated CodeLandScapeActivity 208558586 前*****
2021-01-28 16:25:26.488 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.488 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.488 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.489 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 170876321 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.489 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 3677126 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.490 D/----->: *****Application onActivityCreated CodeLandScapeActivity 208558586 后*****
2021-01-28 16:25:26.490 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.490 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.490 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.490 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 25057159 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.491 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 182490804 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.491 D/----->: CodeLandScapeActivity 208558586 onCreate
2021-01-28 16:25:26.513 D/----->: *****Application onActivityStarted CodeLandScapeActivity 208558586 前*****
2021-01-28 16:25:26.513 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.513 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.513 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.513 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 77197585 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.514 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 19202678 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.514 D/----->: *****Application onActivityStarted CodeLandScapeActivity 208558586 后*****
2021-01-28 16:25:26.514 I/----->: displayMetrics context.getResources() displayMetrics 231932476 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.514 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.514 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.514 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 12988535 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.515 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 170988772 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:26.515 D/----->: CodeLandScapeActivity 208558586 onStart
2021-01-28 16:25:26.516 D/----->: CodeLandScapeActivity 208558586 onResume
2021-01-28 16:25:26.590 D/----->: CodeLandScapeActivity 208558586 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:25:26.596 I/----->: View width = 300,height = 300
2021-01-28 16:25:26.621 I/----->: View width = 300,height = 300
2021-01-28 16:25:26.963 D/----->: CodeLandScapeActivity 12585809 onStop

返回到第一个CodeLandScapeActivity

2021-01-28 16:25:40.993 D/----->: CodeLandScapeActivity 208558586 onPause
2021-01-28 16:25:41.017 D/----->: CodeLandScapeActivity 12585809 onRestart
2021-01-28 16:25:41.018 D/----->: *****Application onActivityStarted CodeLandScapeActivity 12585809 前*****
2021-01-28 16:25:41.018 I/----->: displayMetrics context.getResources() displayMetrics 227119832 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.018 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.018 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.020 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 183379303 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.021 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 192249620 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.022 D/----->: *****Application onActivityStarted CodeLandScapeActivity 12585809 后*****
2021-01-28 16:25:41.022 I/----->: displayMetrics context.getResources() displayMetrics 227119832 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.022 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.023 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.024 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 188179389 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.024 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 136789426 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:41.025 D/----->: CodeLandScapeActivity 12585809 onStart
2021-01-28 16:25:41.027 D/----->: CodeLandScapeActivity 12585809 onResume
2021-01-28 16:25:41.083 I/----->: View width = 300,height = 300
2021-01-28 16:25:41.084 D/----->: CodeLandScapeActivity 12585809 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:25:41.116 I/----->: View width = 300,height = 300
2021-01-28 16:25:41.411 D/----->: CodeLandScapeActivity 208558586 onStop
2021-01-28 16:25:41.413 D/----->: CodeLandScapeActivity 208558586 onDestroy

返回到MainActivity

2021-01-28 16:25:53.750 D/----->: CodeLandScapeActivity 12585809 onPause
2021-01-28 16:25:53.858 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 360,screenHeightDp = 710***** 注意后续打印的context是Application
2021-01-28 16:25:53.858 I/----->: displayMetrics context.getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.858 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.858 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.859 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 255259606 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.860 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 104150615 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.862 D/----->: MainActivity 131104389 onRestart
2021-01-28 16:25:53.874 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 16:25:53.874 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.874 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.874 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.875 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 159438148 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.877 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 57521709 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.878 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 16:25:53.878 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.878 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.878 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.878 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 117864290 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.879 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 233627891 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 16:25:53.879 D/----->: MainActivity 131104389 onStart
2021-01-28 16:25:53.880 D/----->: MainActivity 131104389 onResume
2021-01-28 16:25:53.933 I/----->: View width = 300,height = 300
2021-01-28 16:25:53.933 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 16:25:53.971 I/----->: View width = 300,height = 300
2021-01-28 16:25:54.033 D/----->: CodeLandScapeActivity 12585809 onStop
2021-01-28 16:25:54.034 D/----->: CodeLandScapeActivity 12585809 onDestroy

打开AndroidAutoSize 适配  design_width_in_dp设置为200   design_height_in_dp设置为356 比例 16:9

打开 MainActivity

2021-01-28 17:41:41.423 D/----->: *****Application onActivityCreated MainActivity 131104389 前*****
2021-01-28 17:41:41.424 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.424 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.424 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.425 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 122550932 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.426 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 17103165 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.438 D/----->: !!!!!!!!!!!!! 缓存没有 新建 key = 1073746264
2021-01-28 17:41:41.439 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 17:41:41.439 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 17:41:41.440 D/----->: *****Application onActivityCreated MainActivity 131104389 后*****
2021-01-28 17:41:41.440 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.440 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.440 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.441 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 87876914 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.442 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 258933379 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.444 D/----->: MainActivity 131104389 onCreate
2021-01-28 17:41:41.444 I/----->: StatusBarHeight = 84
2021-01-28 17:41:41.520 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 17:41:41.520 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.520 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.520 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.521 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 231794534 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.522 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 123194023 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.522 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 17:41:41.522 E/----->: setDensity activityDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 17:41:41.522 E/----->: setDensity applicationDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 17:41:41.523 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 17:41:41.523 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.523 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.523 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:41:41.524 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 71981908 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.524 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 41200381 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:41:41.525 D/----->: MainActivity 131104389 onStart
2021-01-28 17:41:41.527 D/----->: MainActivity 131104389 onResume
2021-01-28 17:41:41.581 I/----->: NavigationHeight 227,windowInsets.getSystemWindowInsetBottom = 126,isShowing = false
2021-01-28 17:41:41.719 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 17:41:41.724 I/----->: View width = 540,height = 540
2021-01-28 17:41:41.739 I/----->: View width = 540,height = 540

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

MainActivity打开 XMLLandScapeActivity

2021-01-28 17:42:54.160 D/----->: MainActivity 131104389 onPause
2021-01-28 17:42:54.317 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 17:42:54.318 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 2214 , mScreenHeight = 1080 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 17:42:54.358 D/----->: *****Application onActivityCreated XMLLandScapeActivity 113732573 前*****
2021-01-28 17:42:54.358 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.358 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.358 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.359 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 89385177 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.360 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 109212318 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.360 D/----->: !!!!!!!!!!!!! 缓存没有 新建 key = 1073749666
2021-01-28 17:42:54.360 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 17:42:54.360 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 17:42:54.361 D/----->: *****Application onActivityCreated XMLLandScapeActivity 113732573 后*****
2021-01-28 17:42:54.361 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.361 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.361 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.362 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 145432959 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.363 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 206316876 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.364 D/----->: XMLLandScapeActivity 113732573 onCreate
2021-01-28 17:42:54.444 D/----->: *****Application onActivityStarted XMLLandScapeActivity 113732573 前*****
2021-01-28 17:42:54.444 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.444 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.444 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.445 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 164198780 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.446 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 263500293 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.447 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 17:42:54.447 E/----->: setDensity activityDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 17:42:54.448 E/----->: setDensity applicationDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 17:42:54.448 D/----->: *****Application onActivityStarted XMLLandScapeActivity 113732573 后*****
2021-01-28 17:42:54.448 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.449 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.449 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 17:42:54.449 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 51085914 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.450 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 154803339 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:42:54.450 D/----->: XMLLandScapeActivity 113732573 onStart
2021-01-28 17:42:54.451 D/----->: XMLLandScapeActivity 113732573 onResume
2021-01-28 17:42:54.562 D/----->: MainActivity 131104389 onStop
2021-01-28 17:42:54.576 D/----->: XMLLandScapeActivity 113732573 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 17:42:54.587 I/----->: View width = 1107,height = 996
2021-01-28 17:42:54.616 I/----->: View width = 1107,height = 996

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

application注册的横竖屏切换监听 调换了长宽 ,AndroidAutoSize会基于 横屏的长度/设计图宽 进行缩放适配

返回MainActivity

2021-01-28 17:44:39.723 D/----->: XMLLandScapeActivity 113732573 onPause
2021-01-28 17:44:39.862 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 360,screenHeightDp = 710***** 注意后续打印的context是Application
2021-01-28 17:44:39.863 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 1080 , mScreenHeight = 2214 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 17:44:39.866 D/----->: MainActivity 131104389 onRestart
2021-01-28 17:44:39.870 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 17:44:39.870 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.870 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.871 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.871 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 69775730 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.872 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 194017731 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.872 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 17:44:39.872 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 17:44:39.872 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 17:44:39.873 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 17:44:39.873 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:44:39.873 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.873 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 17:44:39.876 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 24080960 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.877 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 247682425 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 17:44:39.877 D/----->: MainActivity 131104389 onStart
2021-01-28 17:44:39.878 D/----->: MainActivity 131104389 onResume
2021-01-28 17:44:39.931 I/----->: View width = 540,height = 540
2021-01-28 17:44:39.933 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 17:44:40.007 I/----->: View width = 540,height = 540
2021-01-28 17:44:40.038 D/----->: XMLLandScapeActivity 113732573 onStop
2021-01-28 17:44:40.039 D/----->: XMLLandScapeActivity 113732573 onDestroy

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

在 onConfigurationChanged 执行后displayMetrics被重置了,MainActivity之所以正常是因为onStart方法里面又变更了一次参数设置

再打开 XMLLandScapeActivity  再返回

2021-01-28 19:45:15.842 D/----->: MainActivity 131104389 onPause
2021-01-28 19:45:15.936 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 19:45:15.937 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 2214 , mScreenHeight = 1080 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 19:45:15.953 D/----->: *****Application onActivityCreated XMLLandScapeActivity 108299232 前*****
2021-01-28 19:45:15.954 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.954 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.954 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.954 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 211674431 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.955 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 147717644 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.955 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 19:45:15.955 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 19:45:15.955 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 19:45:15.956 D/----->: *****Application onActivityCreated XMLLandScapeActivity 108299232 后*****
2021-01-28 19:45:15.956 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:15.956 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.956 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:15.957 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 207946581 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.957 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 113541482 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:15.958 D/----->: XMLLandScapeActivity 108299232 onCreate
2021-01-28 19:45:16.010 D/----->: *****Application onActivityStarted XMLLandScapeActivity 108299232 前*****
2021-01-28 19:45:16.010 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:16.011 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.011 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:16.012 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 153132079 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.014 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 231932476 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.015 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 19:45:16.015 E/----->: setDensity activityDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 19:45:16.015 E/----->: setDensity applicationDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 19:45:16.019 D/----->: *****Application onActivityStarted XMLLandScapeActivity 108299232 后*****
2021-01-28 19:45:16.019 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:16.019 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.019 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:16.021 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 65956805 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.022 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 12065050 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.023 D/----->: XMLLandScapeActivity 108299232 onStart
2021-01-28 19:45:16.026 D/----->: XMLLandScapeActivity 108299232 onResume
2021-01-28 19:45:16.074 D/----->: MainActivity 131104389 Activity onConfigurationChanged
2021-01-28 19:45:16.074 I/----->: displayMetrics context.getResources() displayMetrics 46878333 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.074 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.075 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 19:45:16.076 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 69775730 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.076 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 194017731 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:16.134 D/----->: MainActivity 131104389 onStop
2021-01-28 19:45:16.142 D/----->: XMLLandScapeActivity 108299232 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 19:45:16.150 I/----->: View width = 1107,height = 996
2021-01-28 19:45:16.186 I/----->: View width = 1107,height = 996

 

2021-01-28 19:45:37.185 D/----->: XMLLandScapeActivity 108299232 onPause
2021-01-28 19:45:37.315 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 360,screenHeightDp = 710***** 注意后续打印的context是Application
2021-01-28 19:45:37.316 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 1080 , mScreenHeight = 2214 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 19:45:37.317 D/----->: MainActivity 131104389 onRestart
2021-01-28 19:45:37.320 D/----->: *****Application onActivityStarted MainActivity 131104389 前*****
2021-01-28 19:45:37.320 I/----->: displayMetrics context.getResources() displayMetrics 46878333 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.320 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.320 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.321 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 204815025 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.321 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 7478166 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.321 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 19:45:37.322 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 19:45:37.322 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 19:45:37.322 D/----->: *****Application onActivityStarted MainActivity 131104389 后*****
2021-01-28 19:45:37.322 I/----->: displayMetrics context.getResources() displayMetrics 46878333 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 19:45:37.322 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.323 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 19:45:37.323 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 16884503 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.324 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 137208580 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.324 D/----->: MainActivity 131104389 onStart
2021-01-28 19:45:37.325 D/----->: MainActivity 131104389 onResume
2021-01-28 19:45:37.352 D/----->: MainActivity 131104389 Activity onConfigurationChanged
2021-01-28 19:45:37.352 I/----->: displayMetrics context.getResources() displayMetrics 132615913 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.352 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.352 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 19:45:37.353 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 207161198 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.354 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 255843855 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 19:45:37.389 I/----->: View width = 540,height = 540
2021-01-28 19:45:37.389 D/----->: MainActivity 131104389 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 19:45:37.445 I/----->: View width = 300,height = 300
2021-01-28 19:45:37.466 D/----->: XMLLandScapeActivity 108299232 onStop
2021-01-28 19:45:37.468 D/----->: XMLLandScapeActivity 108299232 onDestroy

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

在 onConfigurationChanged 执行后displayMetrics被重置了,MainActivity动态添加的view没有缩放


MainActivity打开CodeLandScapeActivity 接着在 手机保持竖屏状态下 再打开一个 CodeLandScapeActivity 然后返回 到第一个 CodeLandScapeActivity

2021-01-28 18:49:46.796 D/----->: MainActivity 131104389 onPause
2021-01-28 18:49:46.924 D/----->: *****Application onActivityCreated CodeLandScapeActivity 113732573 前*****
2021-01-28 18:49:46.924 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.924 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.924 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.925 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 2275104 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.926 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 89385177 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.926 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 18:49:46.926 E/----->: setDensity activityDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:49:46.927 E/----->: setDensity applicationDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:49:46.927 D/----->: *****Application onActivityCreated CodeLandScapeActivity 113732573 后*****
2021-01-28 18:49:46.928 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.928 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.928 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.929 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 109212318 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.929 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 145432959 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.930 D/----->: CodeLandScapeActivity 113732573 onCreate
2021-01-28 18:49:46.978 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 前*****
2021-01-28 18:49:46.978 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.979 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.979 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.980 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 83081801 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.981 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 201244494 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.981 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 18:49:46.981 E/----->: setDensity activityDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:49:46.981 E/----->: setDensity applicationDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:49:46.986 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 后*****
2021-01-28 18:49:46.986 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.986 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.987 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:49:46.989 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 236284015 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.990 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 164198780 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:46.990 D/----->: CodeLandScapeActivity 113732573 onStart
2021-01-28 18:49:46.991 D/----->: CodeLandScapeActivity 113732573 onResume
2021-01-28 18:49:47.091 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 18:49:47.092 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 2214 , mScreenHeight = 1080 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 18:49:47.096 D/----->: CodeLandScapeActivity 113732573 Activity onConfigurationChanged
2021-01-28 18:49:47.097 I/----->: displayMetrics context.getResources() displayMetrics 212596327 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:47.097 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:47.097 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:47.097 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 83196948 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:47.098 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 63708349 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:49:47.126 D/----->: CodeLandScapeActivity 113732573 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 18:49:47.137 I/----->: View width = 540,height = 540
2021-01-28 18:49:47.174 I/----->: View width = 300,height = 300
2021-01-28 18:49:47.208 D/----->: MainActivity 131104389 onStop

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

静态view创建使用的是5.4,在 onConfigurationChanged 执行后displayMetrics被重置了,动态view添加在之后出现 

2021-01-28 18:50:11.304 D/----->: CodeLandScapeActivity 113732573 onPause
2021-01-28 18:50:11.427 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 360,screenHeightDp = 710***** 注意后续打印的context是Application
2021-01-28 18:50:11.428 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 1080 , mScreenHeight = 2214 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 18:50:11.463 D/----->: *****Application onActivityCreated CodeLandScapeActivity 91886148 前*****
2021-01-28 18:50:11.464 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.464 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.464 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.465 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 116457971 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.466 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 136842928 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.466 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 18:50:11.466 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 18:50:11.466 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 5.4
2021-01-28 18:50:11.468 D/----->: *****Application onActivityCreated CodeLandScapeActivity 91886148 后*****
2021-01-28 18:50:11.469 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.469 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.469 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.469 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 162009385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.470 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 8387758 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.471 D/----->: CodeLandScapeActivity 91886148 onCreate
2021-01-28 18:50:11.513 D/----->: *****Application onActivityStarted CodeLandScapeActivity 91886148 前*****
2021-01-28 18:50:11.514 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.514 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.514 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.516 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 173952483 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.517 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 108299232 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.517 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073746264, displayMetricsInfo.getDensity() = 5.4
2021-01-28 18:50:11.517 E/----->: setDensity activityDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:50:11.517 E/----->: setDensity applicationDisplayMetrics 2065927680 旧density = 5.4,变更为 5.4
2021-01-28 18:50:11.519 D/----->: *****Application onActivityStarted CodeLandScapeActivity 91886148 后*****
2021-01-28 18:50:11.519 I/----->: displayMetrics context.getResources() displayMetrics 119504385 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.519 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.519 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 5.4,densityDpi = 864,scaledDensity = 5.4
2021-01-28 18:50:11.521 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 252352153 widthPixels = 1080,heightPixels = 2214,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.522 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 79359326 widthPixels = 1080,heightPixels = 2340,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:11.523 D/----->: CodeLandScapeActivity 91886148 onStart
2021-01-28 18:50:11.526 D/----->: CodeLandScapeActivity 91886148 onResume
2021-01-28 18:50:11.627 D/----->: CodeLandScapeActivity 113732573 onStop
2021-01-28 18:50:11.644 D/----->: CodeLandScapeActivity 91886148 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 18:50:11.647 I/----->: View width = 540,height = 540
2021-01-28 18:50:11.690 I/----->: View width = 540,height = 540
2021-01-28 18:50:12.205 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 18:50:12.207 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 2214 , mScreenHeight = 1080 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 18:50:12.211 D/----->: CodeLandScapeActivity 91886148 Activity onConfigurationChanged
2021-01-28 18:50:12.212 I/----->: displayMetrics context.getResources() displayMetrics 212596327 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:12.212 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:12.212 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:12.215 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 258689037 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:12.216 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 128963522 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

静态view创建使用的是5.4,在 onConfigurationChanged 执行后displayMetrics被重置了,动态view添加在之前出现 

2021-01-28 18:50:48.201 D/----->: CodeLandScapeActivity 91886148 onPause
2021-01-28 18:50:48.223 D/----->: CodeLandScapeActivity 113732573 onRestart
2021-01-28 18:50:48.228 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 前*****
2021-01-28 18:50:48.228 I/----->: displayMetrics context.getResources() displayMetrics 212596327 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.228 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.228 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.230 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 153132079 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.230 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 231932476 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.231 D/----->: !!!!!!!!!!!!! 缓存没有 新建 key = 1073749666
2021-01-28 18:50:48.231 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 18:50:48.231 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 18:50:48.233 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 后*****
2021-01-28 18:50:48.233 I/----->: displayMetrics context.getResources() displayMetrics 212596327 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:50:48.233 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.233 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:50:48.234 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 65956805 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.234 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 12065050 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:50:48.235 D/----->: CodeLandScapeActivity 113732573 onStart
2021-01-28 18:50:48.236 D/----->: CodeLandScapeActivity 113732573 onResume
2021-01-28 18:50:48.303 I/----->: View width = 540,height = 540
2021-01-28 18:50:48.303 D/----->: CodeLandScapeActivity 113732573 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 18:50:48.367 I/----->: View width = 1107,height = 996
2021-01-28 18:50:48.651 D/----->: CodeLandScapeActivity 91886148 onStop
2021-01-28 18:50:48.653 D/----->: CodeLandScapeActivity 91886148 onDestroy

onstart之后动态创建view使用的是横屏长度/设计图宽尺寸

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

MainActivity打开CodeLandScapeActivity 接着在 手机保持横屏状态下 再打开一个 CodeLandScapeActivity 然后返回 到第一个 CodeLandScapeActivity

2021-01-28 18:55:08.280 D/----->: MainActivity 131104389 onPause
2021-01-28 18:55:08.412 D/----->: *****Application onConfigurationChanged newConfig screenWidthDp 738,screenHeightDp = 332***** 注意后续打印的context是Application
2021-01-28 18:55:08.413 D/----->: !!!!!!!!!!!!变更宽高mScreenWidth = 2214 , mScreenHeight = 1080 !!!!!!!!!!!!!!!!!!!!!!!!!!
2021-01-28 18:55:08.479 D/----->: *****Application onActivityCreated CodeLandScapeActivity 113732573 前*****
2021-01-28 18:55:08.480 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.480 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.480 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.482 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 89385177 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.482 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 109212318 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.483 D/----->: !!!!!!!!!!!!! 缓存没有 新建 key = 1073749666
2021-01-28 18:55:08.483 E/----->: setDensity activityDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 18:55:08.483 E/----->: setDensity applicationDisplayMetrics 1147737600 旧density = 3.0,变更为 11.07
2021-01-28 18:55:08.484 D/----->: *****Application onActivityCreated CodeLandScapeActivity 113732573 后*****
2021-01-28 18:55:08.484 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.484 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.484 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.486 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 145432959 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.489 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 206316876 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.490 D/----->: CodeLandScapeActivity 113732573 onCreate
2021-01-28 18:55:08.557 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 前*****
2021-01-28 18:55:08.558 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.558 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.558 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.558 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 164198780 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.559 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 263500293 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.559 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 18:55:08.560 E/----->: setDensity activityDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:08.560 E/----->: setDensity applicationDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:08.561 D/----->: *****Application onActivityStarted CodeLandScapeActivity 113732573 后*****
2021-01-28 18:55:08.561 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.561 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.561 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:08.562 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 51085914 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.563 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 154803339 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:08.564 D/----->: CodeLandScapeActivity 113732573 onStart
2021-01-28 18:55:08.566 D/----->: CodeLandScapeActivity 113732573 onResume
2021-01-28 18:55:08.628 D/----->: MainActivity 131104389 onStop
2021-01-28 18:55:08.638 D/----->: CodeLandScapeActivity 113732573 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 18:55:08.642 I/----->: View width = 1107,height = 996
2021-01-28 18:55:08.666 I/----->: View width = 1107,height = 996

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

2021-01-28 18:55:39.427 D/----->: CodeLandScapeActivity 113732573 onPause
2021-01-28 18:55:39.459 D/----->: *****Application onActivityCreated CodeLandScapeActivity 33335510 前*****
2021-01-28 18:55:39.459 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.460 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.460 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.460 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 186822445 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.461 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 150109282 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.461 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 18:55:39.461 E/----->: setDensity activityDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:39.461 E/----->: setDensity applicationDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:39.462 D/----->: *****Application onActivityCreated CodeLandScapeActivity 33335510 后*****
2021-01-28 18:55:39.462 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.462 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.462 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.463 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 116457971 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.464 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 136842928 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.464 D/----->: CodeLandScapeActivity 33335510 onCreate
2021-01-28 18:55:39.486 D/----->: *****Application onActivityStarted CodeLandScapeActivity 33335510 前*****
2021-01-28 18:55:39.486 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.486 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.486 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.486 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 154844573 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.487 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 137806354 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.487 D/----->: !!!!!!!!!!!!! 缓存找到 key = 1073749666, displayMetricsInfo.getDensity() = 11.07
2021-01-28 18:55:39.487 E/----->: setDensity activityDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:39.487 E/----->: setDensity applicationDisplayMetrics -60293776 旧density = 11.07,变更为 11.07
2021-01-28 18:55:39.488 D/----->: *****Application onActivityStarted CodeLandScapeActivity 33335510 后*****
2021-01-28 18:55:39.488 I/----->: displayMetrics context.getResources() displayMetrics 2275104 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.488 I/----->: displayMetrics Resources.getSystem() displayMetrics 110306470 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.488 I/----->: displayMetrics getApplicationContext().getResources() displayMetrics 3497703 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 11.07,densityDpi = 1771,scaledDensity = 11.07
2021-01-28 18:55:39.489 I/----->: displayMetrics context.getSystemService.getDefaultDisplay() displayMetrics 173952483 widthPixels = 2214,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.489 I/----->: displayMetrics context.getSystemService.getRealMetrics displayMetrics 108299232 widthPixels = 2340,heightPixels = 1080,xdpi = 403.411,ydpi = 401.594,density = 3.0,densityDpi = 480,scaledDensity = 3.0
2021-01-28 18:55:39.489 D/----->: CodeLandScapeActivity 33335510 onStart
2021-01-28 18:55:39.490 D/----->: CodeLandScapeActivity 33335510 onResume
2021-01-28 18:55:39.546 D/----->: CodeLandScapeActivity 33335510 !!!!!!!!!动态add!!!!!!!!!
2021-01-28 18:55:39.551 I/----->: View width = 1107,height = 996
2021-01-28 18:55:39.584 I/----->: View width = 1107,height = 996
2021-01-28 18:55:39.894 D/----->: CodeLandScapeActivity 113732573 onStop

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

 

更复杂的旋转来回进出将会出现更多的缩放变动。

 

综上测试:

动态横竖屏的切换、不同横竖屏页面之间的来回跳转、View静动态加载方式 等都会使AndroidAutoSize的缩放倍数发生变化。

5、调整优化

1、横屏的页面是否也可以按照竖屏的放大比率适配?

如果可行    那么直接去掉AndroidAutoSize 库中application.registerComponentCallbacks onConfigurationChanged 中对于mScreenWidth和mScreenHeight的修改即可去除某些情况下缩放变化问题

2、onConfigurationChange会重置displayMetrics导致动态添加的View缩放不一致

所以 onConfigurationChange监听里面也追加一次参数修改 AutoSize.autoConvertDensityOfGlobal(this) 可以保证动态添加的View缩放比一致

 

以上两处调整后,缩放比稳定,测试验证有效。

 

1修改通过无论横竖屏始终使用   手机短边长度/设计图短边长度  来确保缩放比率的一致  就要求不能完全照搬设计图各控件的宽。比如设计图是16:9比例 短边1080 x 1920px 算 360dp x 640dp  如果某个ui控件铺满则宽度填640dp,那么在1080 x 2200的手机上就留白,在1080 x 1800 手机上将越界。 另一方面设备的长宽比差异,导航栏差异、设备获取差异导致 没有办法按长边计算适配,为了修复上述问题,使用1方案在宽维度上不能照搬设计图宽,还是需要搭配使用 matchParent 、wrap_content、gravity

因为AndroidAutoSize 改变了dp px转换工具,所以app的dp px转换工具类也需要做相应修改。

6、思考与讨论

1、正是因为activity共用displayMetrics,所以cancelAdapt需要还原初始参数。

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

2、在手机、平板上完全按照等比缩放设计图的方式去显示是否符合自家 UI的设计要求?

3、因为有测试中的bug,如果只按照短边适配,那么横屏下的ui控件和竖屏状态下的宽高是一致的,UI是否接受,可以横屏也可以竖屏的这种动态页面写ui有什么注意点?

4、如若完全使用AndroidAutoSize机制,完全不用matchParent 和wrapContent,所有的页面控件宽高都照搬设计稿尺寸,后续一旦去除的成本会很高,并且将完全不可以对缩放比作修改。

5、平板尺寸大,设备屏幕密度与真实的相差也比较大。所以在平板上的页面完全按照手机上等比缩放会显得特别大。

例如 如下代码通过 修改设计图尺寸 限制 缩放比率 ,可以使的控件在平板上略微放大,但同样引入问题3,如果一个页面完全照搬设计图写的宽高dp值,那么限制缩放比率可能将使得控件显示区域不能铺满 屏幕上将留白

平板适配 AndroidAutoSize 完全解析,踩坑测试 与 使用注意事项总结

6、如果想使用AndroidAutoSize的缩放机制 而又 不完全被 限制死 那么 在布局的编写上有没有什么操作空间 以及注意的地方

 

UI需求的统一才能开发的统一,选择了一个方案可能得接受随之而来的缺点,在 UI需求与开发方案的一致的基础上找到平衡点 才能选择适合自己的屏幕适配方案。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

上一篇:Android 屏幕适配


下一篇:Android显示单元--像素、分辨率、颜色