【发布时间】:2021-08-31 21:50:41
【问题描述】:
如何使用 compose 获取实际大小值?如果在将数据提供给视图之前必须完成布局大小的操作?我不喜欢检查。当每次画布重绘时
Box {
var count by rememberSaveable {
mutableStateOf(0)
}
var states = remember { mutableListOf<Rain>() }
Canvas(modifier = Modifier.fillMaxSize()) {
// i need the canvas' size so i initialize the object inside this scope, and check it every time when canvas redraws
Log.e("canvas", "repainted")
if(states.isEmpty()) states.addAll(MutableList(300) {
Rain(size.width, size.height)
})
drawRect(color = Color.Black)
repeat(300) {
val c = count
val x1 = states[it].x1
val x2 = states[it].x2
val y1 = states[it].y1
val y2 = states[it].y2
val color = states[it].color
drawLine(start = Offset(x1, y1), end = Offset(x2, y2), color = color)
states[it]()
}
}
LaunchedEffect(isPaused) {
while (!isPaused) {
delay(40)
count++
}
}
}
【问题讨论】:
标签: android kotlin android-jetpack-compose