我就是想达到这样的效果

enter image description here

其中A是图像,B也是图像.

目前,这是我能做的最好的了

 Card(
   modifier = Modifier
   .fillMaxWidth()
   .constrainAs(image) {
     top.linkTo(parent.top)
     start.linkTo(parent.start)
     end.linkTo(parent.end)
     width = Dimension.fillToConstraints}.fillMaxSize(0.3f)) {
       Row {
         AsyncImage(model = url1,
                    contentDescription = "Product Image",
                    modifier = Modifier.weight(1f),
                    contentScale = ContentScale.Crop
                    )

         AsyncImage(model = url2,
                    contentDescription = "Product Image",
                    modifier = Modifier.weight(1f),
                    contentScale = ContentScale.Crop
                    )
                }
            }
      }
}

It will split these 2 images vertically, but not diagonally like below picture. enter image description here

任何帮助都将不胜感激.

谢谢

推荐答案

可以使用Shape和Modifier.graphicsLayer{}来实现这一点,使用Clip和Shape或Modifier.clip(shape)来实现这一点,后者是发动机罩下的GraphicsLayer.

@Composable
private fun DividedImageCard() {
   Card() {
       Box(
           modifier = Modifier
               .fillMaxWidth()
               .height(200.dp)
       ) {

           val shapeLeft = GenericShape { size: Size, layoutDirection: LayoutDirection ->
               val width = size.width
               val height = size.height
               moveTo(0f, height)
               lineTo(0f, 0f)
               lineTo(width, 0f)
               close()
           }

           val shapeRight = GenericShape { size: Size, layoutDirection: LayoutDirection ->
               val width = size.width
               val height = size.height
               moveTo(width, 0f)
               lineTo(width, height)
               lineTo(0f, height)
               close()
           }

           val modifierLeft = Modifier
               .fillMaxWidth()
               .height(200.dp)
               .graphicsLayer {
                   clip = true
                   shape = shapeLeft
               }
               .border(3.dp, Color.Green)


           val modifierRight = Modifier
               .fillMaxWidth()
               .height(200.dp)
               .graphicsLayer {
                   clip = true
                   shape = shapeRight
               }
               .border(3.dp, Color.Red)

           Image(
               modifier = modifierLeft,
               painter = painterResource(id = R.drawable.landscape1),
               contentDescription = null,
               contentScale = ContentScale.FillBounds
           )

           Image(
               modifier = modifierRight,
               painter = painterResource(id = R.drawable.landscape2),
               contentDescription = null,
               contentScale = ContentScale.FillBounds
           )
       }
   }
}

结果

enter image description here

Android相关问答推荐

将Any强制转换为Integer将从API返回NullPointerException

如何让用户与我的应用生成的多个音频文件交互

Jetpack编写Lazy列滑动删除动画不顺利结束

如何将结果从viewModelScope传递到活动

如何制作带有图标和文本的Fab

如何将Unicode符号作为文本居中放置在布局中的按钮(Android XML)中?

为什么 Android Compose 将片段作为参数传递给 Composables 函数?

当提供非状态对象时,compose 如何进行重组

Android studio应用判断无法打开离线数据库

如何在Android Studio中禁用文件中的Github用户名引用?

Android Compose 为什么 Checkbox 在父对象可点击时需要 onCheckChanged?

如何仅使用您的 Android 应用程序定位平板电脑?

[Android][Room] 将密封类存储到 Room 数据库中

如何从包装在泛型中的 retrofit 调用中检索密钥?

在事件中使用 Context/Toast 时不需要的重组 - Jetpack Compose

为什么项目捕获对象给我在 Compose 中找不到参考

Jetpack compose 为网络检索视频帧导致延迟

如何从日期 Select 器计算年龄?

如何在 compose 中使用 BottomSheetScaffold 为底页设置半展开高度?

为什么在try 实例化 Mediaplayer 时会出现 NullPointerException?安卓Kotlin