使 AndroidView 将触摸事件传播到底层 Composable

时间:2021-03-15 16:55:42

标签: android android-view android-jetpack-compose

具有以下布局,即使 Button 覆盖整个屏幕,是否可以使 AndroidView(或 AndroidView 下的任何其他视图)接收触摸事件?我能够使用两个 Composable 或两个老式 View 使其工作,但不能使用 ComposableView

@Composable
fun SomeScreen() {
    Box(
        contentAlignment = Alignment.Center,
        modifier = Modifier.fillMaxSize()
    ) {
        Button(
            onClick = {}
        ) {
            Text(text = "Button")
        }
        AndroidView(
            viewBlock = {
                View(it).apply {
                    setBackgroundResource(android.R.color.transparent)
                    layoutParams = ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                }
            }
        )
    }
}

0 个答案:

没有答案
相关问题