我知道可以使用自定义视图而不是 Google 地图中的基本地图标记来执行此答案中所述的操作。我很好奇是否可以通过 Compose 达到类似的效果?
由于ComposeView是最后一堂课,无法直接扩展它,所以我正在考虑有一个FrameLayout可以将其作为子项添加的课程。尽管这似乎会导致竞争条件,因为可组合项的绘制与普通 android 略有不同View。
class MapMarkerView : FrameLayout {
constructor(context: Context) : super(context) {
initView()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initView()
}
private fun initView() {
val composeView = ComposeView(context).apply {
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
}
composeView.setContent {
// this runs asynchronously making the the bitmap generation not include composable at runtime?
Text(text = "2345", modifier = Modifier.background(Color.Green, RoundedCornerShape(4.dp)))
}
addView(composeView)
}
}
Run Code Online (Sandbox Code Playgroud)
我读过的大多数文章都有一些用于生成这样的位图的回调函数 …