简体   繁体   English

AndroidView 在 Jetpack Compose 的 Box 中始终位于顶部

[英]AndroidView always on top in Box in Jetpack Compose

This is my code这是我的代码

        setContent {
            Box(modifier = Modifier.fillMaxSize()){
                AndroidView(factory = { unityView }) //this view is UnityPlayer
                //other view
                Button() // this Button is below AndroidView
            }
        }

The AndroidView is always on top AndroidView 总是在顶部

You have to add a row or column modifier before using the Box在使用 Box 之前,您必须添加行或列修饰符

@Composable
fun AlignInColomn() {
    Column(
        modifier = Modifier
            .size(150.dp)
            
        horizontalArrangement = Arrangement.End,
        verticalAlignment = Alignment.CenterVertically
    ) {
        Box(modifier = Modifier.fillMaxSize()){
                AndroidView(factory = { unityView })       
            }
        //other view
        Button() 
    }
}

You can also create by using these line of codes:您还可以使用以下代码行创建:

Box(modifier = Modifier.fillMaxSize()){
  Box(modifier = Modifier.fillMaxSize()){
    AndroidView(factory = { unityView })
  }

  Box(modifier = Modifier.fillMaxSize().align(Alignment.BottomCenter)){
    // Place all other view here...
    Button() // Now Button is above the AndroidView
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM