技术栈

【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拆分原则
相关推荐
程序员码歌
6 小时前
【零代码AI编程实战】AI灯塔导航-总结篇
android·前端·后端
书弋江山
8 小时前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
来来走走
10 小时前
Flutter开发 webview_flutter的基本使用
android·flutter
Jerry说前后端
11 小时前
Android 组件封装实践:从解耦到架构演进
android·前端·架构
louisgeek
12 小时前
Android OkHttp Interceptor
android
大王派来巡山的小旋风
12 小时前
Kotlin基本用法三
android·kotlin
Jerry说前后端
12 小时前
Android 移动端 UI 设计:前端常用设计原则总结
android·前端·ui
bytebeats
12 小时前
Jetpack Compose 1.9: 核心新特性简介
android·android jetpack
Icey_World
12 小时前
Mysql笔记-错误条件\处理程序
android
大王派来巡山的小旋风
13 小时前
Kotlin基本用法之集合(一)
android·程序员·kotlin
热门推荐
01UV安装并设置国内源02Qwen3-Coder 快速上手教程 | Qwen Code + Claude Code03【2025.08.06最新版】Android Studio下载、安装及配置记录(自动下载sdk)04KGG转MP3工具|非KGM文件|解密音频05蜘蛛磁力 搜索引擎大全,如何使用蜘蛛磁力查找磁力链接062025最新国内服务器可用docker源仓库地址大全(2025年8月更新)07NVIDIA显卡驱动、CUDA、cuDNN 和 TensorRT 版本匹配指南08TRAE 规则(Rules)配置指南:个人习惯、团队规范与最佳实践09阿里开源首个图像生成基础模型——Qwen-Image本地部署教程,超强中文渲染能力刷新SOTA!10TRAE Rules 实践:为项目配置 6A 工作流