【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 }
}
相关推荐
csj5044 分钟前
安卓基础之《(6)—Activity组件(3)》
android
怀旧,1 小时前
【Linux系统编程】13. Ext系列⽂件系统
android·linux·缓存
Dabei1 小时前
Android 语音助手简单实现与语音助手“执行任务”交流
android·前端
jzlhll1231 小时前
android NDSDManager onResolveFailed errorCode=3的解决方案
android
芦半山2 小时前
四年之后,重新审视 MTE:从硬件架构到工程落地
android·安全
2501_916007472 小时前
iOS与Android符号还原服务统一重构实践总结
android·ios·小程序·重构·uni-app·iphone·webview
allk552 小时前
Android 屏幕适配全维深度解析
android·性能优化·界面适配
Android系统攻城狮2 小时前
Android ALSA驱动进阶之获取采样格式位宽snd_pcm_format_width:用法实例(九十八)
android·pcm·音频进阶·alsa驱动
莫比乌斯环2 小时前
【日常随笔】Android 跳离行为分析 - Instrumentation
android·架构·代码规范
aningxiaoxixi2 小时前
android 媒体之 MediaSession
android·媒体