[英]Jetpack Compose place composable with bigger size inside another composable
so I want to have a Box as a window with another box in it which is bigger than the outermost Box.所以我想有一个盒子作为一个窗口,里面有另一个比最外面的盒子大的盒子。 Then I want to have the inner Box draggable, so I can move it around inside the outermost box.
然后我想让内框可以拖动,这样我就可以在最外面的框内移动它。
My Code looks like this:我的代码如下所示:
Box(modifier = Modifier
.size(100f.dp, 100f.dp)
.border(2f.dp, Color.Black, RectangleShape)
.clipToBounds()
){
val offsetX = remember { mutableStateOf(0f) }
val offsetY = remember { mutableStateOf(0f) }
Box(modifier = Modifier
.offset(offsetX.value.dp, offsetY.value.dp)
.size(600f.dp, 700f.dp)
.background(Color.Blue) //DEBUG
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
offsetX.value += dragAmount.x
offsetY.value += dragAmount.y
}
}
){
//Contents of inner box
}
}
The problem is now, that the inner box is that the inner box is still only as big as the outer box.现在的问题是,内盒是内盒仍然只有外盒那么大。 So I can drag the inner box around but see that the background of the inner blue box is only as wide and high as the outer box.
所以我可以拖动内框,但看到内蓝色框的背景仅与外框一样宽和高。
Is there another modifier to use, wo enable bigger composables inside other smaller composables?是否有其他修饰符可以使用,可以在其他较小的可组合物中启用更大的可组合物?
After a (long) bit of trying (I hate GUI...) here's my solution:经过(长时间)尝试(我讨厌 GUI ......)这是我的解决方案:
With .wrapContentSize(unbounded = true)
set in the parent composable, the child composable can have a bigger size.在父可组合项中设置
.wrapContentSize(unbounded = true)
后,子可组合项可以具有更大的大小。
But make sure to set this modifier after .clipToBounds
because otherwise the content won't clip as wished但请确保在
.clipToBounds
之后设置此修饰符,否则内容将无法按预期剪辑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.