技术栈

【Android】setLayoutParams Sometimes Not Working

命运之手2024-10-25 20:48

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 }
}
上一篇:Unity引擎:游戏开发的核心力量
下一篇:微服务-CAP和AKF拆分原则
相关推荐
火柴就是我
10 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工
16 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心
17 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心
17 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker
19 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴
20 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜
2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker
2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq9527
2 天前
Andorid Google 登录接入文档
android
黄林晴
2 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack
热门推荐
01GitHub 镜像站点02OpenClaw 使用和管理 MCP 完全指南03OpenClaw + 飞书(Feishu)环境搭建指南04Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services05小黑课堂计算机二级WPSoffice题库软件下载安装教程(2026年3月最新版)06Clawdbot部署教程:解决‘gateway token missing’授权问题的完整步骤07OpenClaw优化飞书API 额度已耗尽问题08Window 10部署openclaw报错node.exe : npm error code 12809【OpenClaw 本地实战 Ep.3】突破瓶颈:强制修改 openclaw.json 解锁 32k 上下文记忆10OpenClaw大龙虾机器人完整安装教程