【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 }
}
相关推荐
段娇娇22 分钟前
Android jetpack ViewBinding(一)使用篇
android·android jetpack
筱顾大牛32 分钟前
黑马点评---用户签到、UV统计
android·服务器·uv
耶叶33 分钟前
Android开发实战:通过网络电子书阅读器实践运用fragment知识
android·jvm
00后程序员张42 分钟前
iPhone 无需越狱文件管理 使用Keymob查看导出文件
android·ios·小程序·https·uni-app·iphone·webview
kcuwu.42 分钟前
Python文件操作零基础及进阶
android·服务器·python
锋风Fengfeng1 小时前
Windows怎么方便查看AOSP代码
android·windows
2501_916008891 小时前
Unity3D iOS 应用防篡改实战 资源校验、 IPA 二进制保护
android·ios·小程序·https·uni-app·iphone·webview
Kapaseker1 小时前
Compose 中 CompositionLocalProvider 到底是干啥的
android·kotlin
mg6681 小时前
安卓玩机工具----安卓设备adb调试图形化工具推荐 支持mac与windows
android·adb
wzl202612131 小时前
多账号协同与任务分发:用企微API搭建总部-门店统一运营中台
android·企业微信