WindowManager & DisplayMatrix

本文介绍了如何使用Android系统的API来获取屏幕的宽度、高度、像素密度等信息,并提供了获取DisplayMetrics对象的具体方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// get window manager
WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

// get display matrix of window
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

// 还可以用以下方法获得displaymetrix
context.getResources().getDisplayMetrix()

// DisplayMetrix 有下列property:
public float density;
public int densityDpi;
public int heightPixels;
public float scaledDensity; // 用来做sp与px的转化
public int widthPixels;
public float xdpi;
public float ydpi;

07-31 10:23:38.923236 3282 5623 D LogicalDisplayExt: set displayInfo flag FLAG_ROTATES_WITH_CONTENT 07-31 10:23:38.923283 3282 5623 D LogicalDisplayMapperExtImpl: setMainDisplayUniqueId+ 07-31 10:23:38.923287 3282 5623 D LogicalDisplayMapperExtImpl: setMainDisplayUniqueId- 07-31 10:23:38.923337 3282 5623 I LogicalDisplayMapper: Applying layout: [{dispId: 0(ON), displayGroupName: , addr: {port=131, model=0x40446d8c8efefc}, mThermalBrightnessThrottlingMapId: null, mRefreshRateZoneId: null, mLeadDisplayId: -1, mLeadDisplayAddress: null, mThermalRefreshRateThrottlingMapId: null, mPowerThrottlingMapId: null}], Previous layout: [{dispId: 0(ON), displayGroupName: , addr: {port=131, model=0x40446d8c8efefc}, mThermalBrightnessThrottlingMapId: null, mRefreshRateZoneId: null, mLeadDisplayId: -1, mLeadDisplayAddress: null, mThermalRefreshRateThrottlingMapId: null, mPowerThrottlingMapId: null}] 07-31 10:23:38.923368 3282 5623 I LogicalDisplayMapper: Setting new display group 0 for display 4, from previous group: null 07-31 10:23:38.923407 3282 5623 D LogicalDisplayExt: set displayInfo flag FLAG_ROTATES_WITH_CONTENT 07-31 10:23:38.924356 3282 5623 W DisplayPowerController[display=4]: Screen brightness nits configuration is unavailable; falling back 07-31 10:23:38.924487 3282 5623 D BrightnessMappingStrategyExtImpl: create OplusMappingStrategy. 07-31 10:23:38.924588 3282 5623 D BrightnessMappingStrategyExtImpl: create OplusMappingStrategy. 07-31 10:23:38.924639 3282 5623 D BrightnessMappingStrategyExtImpl: create OplusMappingStrategy. 07-31 10:23:38.924701 3282 5623 D DisplayPowerController[display=4]: DPC construct virtual:com.oplus.olc,1000,olc_mediaProjection,1 mIsPrimaryDisplay:false 07-31 10:23:38.925032 3282 5623 D DisplayManagerServiceExtImpl: scheduleTraversalLocked intraversal=false 07-31 10:23:38.925087 3282 5623 I DisplayManagerServiceExtImpl: handle logical display changed logicalDisplay=id=4,stack=4,content=false,displayInfo{stack=4,type=5,id=4,uId=virtual:com.oplus.olc,1000,olc_mediaProjection,1,state=UNKNOWN,pkg=com.oplus.olc} 07-31 10:23:38.925213 3282 5623 V WindowManager: Content Recording: Handle incoming session on display 4, with a pre-existing session null 07-31 10:23:38.925255 3282 3387 D DisplayManagerService: Delivering display event: displayId=4, event=EVENT_DISPLAY_CONNECTED 07-31 10:23:38.925344 3282 3389 I SurfaceControl: setPosition: sc Surface(name=Surface(name=49c5b96 com.oplus.logkit/com.oplus.logkit.collect.activity.CollectActivity)/@0x801e304 - animation-leash of window_animation)/@0xca61534 tx=14096082684479 x=0.0 y=2433.6829 ,layerId= 1091 caller=SurfaceControl.java.setPosition:3624 SurfaceControl.java.setMatrix:3980 WindowAnimationSpec.java.apply:139 SurfaceAnimationRunner.java.applyTransformation:372 SurfaceAnimationRunner.java.lambda$startAnimationLocked$3:280 null.$r8$lambda$XKYbomSeJZ5X1QvoC6W5WshA39k:0 D8$$SyntheticClass.onAnimationUpdate:0 Animator.java.lambda$static$4:952 D8$$SyntheticClass.call:0 Animator.java.callOnList:763 07-31 10:23:38.925524 3282 5623 D WallpaperControllerExtImpl: handleWallpaperCreated: mLastWallPaperId = 3 高通定屏日志解释与分析
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值