【Android】setLayoutParams Sometimes Not Working

setLayoutParams may fail when called during another layout period

or inner of a callback function in layout period

we can use post to setLayoutParams in next layout period

kotlin 复制代码
binding.image.post {
    val fixedHeight = (binding.image.measuredWidth / ratio).toInt()
    binding.image.setLayoutParams { height = fixedHeight }
}
相关推荐
鹏多多25 分钟前
flutter睡眠与冥想数据可视化神器:sleep_stage_chart插件全解析
android·前端·flutter
勇气要爆发1 小时前
【第五阶段-高级特性和架构】第三章:高级状态管理—GetX状态管理篇
android·架构
未来之窗软件服务3 小时前
服务器运维(十五)自建WEB服务C#PHP——东方仙盟炼气期
android·服务器运维·东方仙盟·东方仙盟sdk·自建web服务
Zender Han8 小时前
Flutter 新版 Google Sign-In 插件完整解析(含示例讲解)
android·flutter·ios·web
来来走走11 小时前
Android开发(Kotlin) LiveData的基本了解
android·开发语言·kotlin
。puppy12 小时前
MySQL 远程登录实验:通过 IP 地址跨机器连接实战指南
android·adb
dongdeaiziji12 小时前
深入理解 Kotlin 中的构造方法
android·kotlin
风起云涌~13 小时前
【Android】浅谈Navigation
android
游戏开发爱好者813 小时前
iOS 商店上架全流程解析 从工程准备到审核通过的系统化实践指南
android·macos·ios·小程序·uni-app·cocoa·iphone
QuantumLeap丶15 小时前
《Flutter全栈开发实战指南:从零到高级》- 18 -自定义绘制与画布
android·flutter·ios