android 在 Activity 的 onCreate 中获取View 的宽高

view 的 post 执行时,首先会判断view 的 mAttatchInfo 是否为空,如果不为空,则将Runnable 添加到mAttachInfo.handler 的 UI线程MessageQueue 中;如果为空,则先将Runnable 暂存在view 的类为HandlerActionQueue的mRunQueue中,在ViewRootImpl 中第一次执行performTransval时执行 dispatchAttachedToWindow ,在这个方法中执行 mRunQueue.executeActions(mAttachInfo.handler),这样就能保证Runnable 运行时获取到获取到view的宽高,因为这个时候首次performTransval已经执行完,首次测量工也会执行完,之后才会执行这个Runnable,所以这个时候能获取到宽高

相关推荐
天空之城--27 分钟前
Android Flutter行业动态与学习参考(2026年8月)
android·flutter
quantdash_cc1 小时前
基于 QuantDash 5 分钟 K 线的网格交易策略参数网格搜索寻优实战
android·开发语言·pandas·量化·quantdash
杉氧2 小时前
原生交互:如何在 Flutter 中嵌入 Android/iOS 原生组件并解决手势冲突
android·flutter·dart
Android打工仔3 小时前
Continuation 的链式关系 —— 一个 suspend 函数如何把结果交还给调用者?
android·kotlin
hunterandroid3 小时前
[Android 从零到一] Kotlin Channel 与复杂并发场景:从生产者-消费者到结构化并发治理
android
FlightYe3 小时前
linux系统编程(八):阻塞与非阻塞IO对比
android·linux·运维·服务器·github·vim
恋猫de小郭4 小时前
Flutter iOS Deep Link 为什么会突然失效:一系列难以言喻的问题
android·前端·flutter
Kapaseker4 小时前
小白都看得懂的 Skill 教程 - 初识 Skill
android·kotlin·vibecoding
神奇小梵4 小时前
安全和开发的需要了解的知识————下载内容的安全,和下载内容如何运行
android·windows·安全·个人开发
2501_915909065 小时前
iOS 证书创建与管理 类型限制 p12 密码与云备份实操
android·ios·小程序·https·uni-app·iphone·webview