gpt4 book ai didi

android - 不要在 Compose 中裁剪 AndroidView 的边界

转载 作者:行者123 更新时间:2023-12-05 01:56:03 25 4
gpt4 key购买 nike

来自 AndroidView documentation :

AndroidView will clip its content to the layout bounds, as being clipped is a common assumption made by Views - keeping clipping disabled might lead to unexpected drawing behavior. Note this deviates from Compose's practice of keeping clipping opt-in, disabled by default.

这似乎表明有一种方法可以关闭裁剪,但我无法做到这一点。

我试过:

  • Modifier.graphicsLayer(clip = false)AndroidView
  • clipToPadding = falseView
  • clipToOutline = falseView
  • clipChildren = falseView

是否可以关闭剪辑?

最佳答案

这是一个已知的 feature request , 这是实现前的解决方法:

@Composable
fun <T : View> AndroidView(
clipToBounds: Boolean,
factory: (Context) -> T,
modifier: Modifier = Modifier,
update: (T) -> Unit = NoOpUpdate,
) {
androidx.compose.ui.viewinterop.AndroidView(
factory = factory,
modifier = modifier,
update = if (clipToBounds) {
update
} else {
{
(it.parent as? ViewGroup)?.clipChildren = false
update(it)
}
}
)
}

关于android - 不要在 Compose 中裁剪 AndroidView 的边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69968037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com