在自定义布局中定位充气的视图
我写了一个继承自RelativeLayout的自定义布局。
它有一个方法(在布局被膨胀后调用),当被调用时会膨胀一个视图,将其附加到布局,然后将其与布局相关联。
但是,当我尝试设置布局参数时,它似乎什么都不做:
fun createCell() { // Inflate a cell and attach it to this val cell = inflate(context, eventCellId, this) // Setup layout params for the cell val params = RelativeLayout.LayoutParams(400, 400) // Lets force it to be 200 from the top params.topMargin = 200 // Set the cell layout params cell.layoutParams = params }
我也试过这个:
fun createCell() { // Inflate a cell and attach it to this val cell = inflate(context, eventCellId, this) cell.top = 200 cell.bottom = 400 }
单元格正在渲染,它只是不在指定的位置渲染。 我是否需要重写onMeasure或其他东西(即使在添加这些单元格之前,我的布局已经膨胀了)。 单元格在运行时动态添加。
- 如何在Java中轻松使用Kotlin渠道生产者?
- 谷歌视觉框架分为两个
- 如何将ByteArray转换为Kotlin中指定字符集的字符串
- Kotlin代码如何在Android应用程序中执行,它与Java有什么不同?
- 在ConstraintLayout中使用组来侦听多个视图上的点击事件
- Android Studio / Kotlin – 无效错误“覆盖方法应该调用超级”
- Retrofit2 + Kotlin中的SimpleXML:MethodException:注释必须标记一个set或get方法
- 如何将UTC日期转换为Android上的区域GMT时间
- 在kotlin中尝试makeSceneTransitionAnimation