【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 }
}
相关推荐
用户20187928316727 分钟前
📚 Android Settings系统:图书馆管理员的故事
android
青莲84341 分钟前
Android 事件分发机制 - 事件流向详解
android·前端·面试
火柴就是我1 小时前
学习一些常用的混合模式之BlendMode. dst_atop
android·flutter
火柴就是我2 小时前
学习一些常用的混合模式之BlendMode. dstIn
android·flutter
ganshenml3 小时前
【Android】 开发四角版本全解析:AS、AGP、Gradle 与 JDK 的配套关系
android·java·开发语言
我命由我123453 小时前
Kotlin 运算符 - == 运算符与 === 运算符
android·java·开发语言·java-ee·kotlin·android studio·android-studio
摘星编程4 小时前
【RAG+LLM实战指南】如何用检索增强生成破解AI幻觉难题?
android·人工智能
火柴就是我4 小时前
学习一些常用的混合模式之BlendMode. dst
android·flutter
遥不可及zzz4 小时前
解决 Google Play 提示的 16KB 内存页面大小对齐问题:通过升级 Android Gradle 插件(AGP)
android
SmartRadio5 小时前
在MT8791 5G硬件平台上舍弃安卓系统-运行OpenWRT系统
android·5g·mt8791