【发布时间】:2021-10-02 09:28:34
【问题描述】:
我正在尝试截屏以下可组合。
它目前几乎可以工作,但是屏幕上的玩家被拖动后的新位置不会出现在屏幕截图中。
FourFourTwo 和 FourFiveOneFormation 组合包含 Player 组合。
var capturingViewBounds by remember { mutableStateOf<Rect?>(null) }
val context = LocalContext.current
var view = LocalView.current
Column(
modifier = Modifier
.padding(top = 8.dp)
.height(390.dp)
.width(300.dp)
.onGloballyPositioned {
capturingViewBounds = it.boundsInRoot()
},
horizontalAlignment = Alignment.CenterHorizontally
) {
when (currentFormation) {
1 -> {
FourFourTwoFormation(
state = state,
events = events
)
}
2 -> {
FourFiveOneFormation(
state = state,
events = events
)
}
}
val bounds = capturingViewBounds ?: return@clickable
bitmap = Bitmap.createBitmap(
bounds.width.roundToInt(), bounds.height.roundToInt(),
Bitmap.Config.ARGB_8888
).applyCanvas {
translate(-bounds.left, -bounds.top)
view.draw(this)
}
我的播放器组合看起来像这样
Column(
modifier = Modifier
.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
offsetX.value = (offsetX.value + dragAmount.x)
offsetY.value = (offsetY.value + dragAmount.y)
}
}
我希望屏幕截图看起来像左边,但现在看起来像右边
【问题讨论】:
标签: android kotlin android-jetpack-compose android-jetpack