kotlin - How to clip the content to match to the corner of a Card in Compose? - Stack Overflow

How can I clip the content to match the corner of the Card.@Composablefun PreviewWindow() {Card {Colu

How can I clip the content to match the corner of the Card.

@Composable
fun PreviewWindow() {
    Card {
        Column(
            modifier = Modifier
                .padding(2.dp)
                .background(Color.Blue)
                .width(200.dp)
                .aspectRatio(1F)
        ) { }
    }
}

Look at the corners of the Card. I want them to clip at the padding. The CardDefalts has shape but I can't get corner radius.Thus it is not very dynamic.

I know that I can set custom shape to achieve this. But I want to know any dynamic solution.

How can I clip the content to match the corner of the Card.

@Composable
fun PreviewWindow() {
    Card {
        Column(
            modifier = Modifier
                .padding(2.dp)
                .background(Color.Blue)
                .width(200.dp)
                .aspectRatio(1F)
        ) { }
    }
}

Look at the corners of the Card. I want them to clip at the padding. The CardDefalts has shape but I can't get corner radius.Thus it is not very dynamic.

I know that I can set custom shape to achieve this. But I want to know any dynamic solution.

Share Improve this question asked Mar 22 at 11:49 SurendraSurendra 236 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The issue occurs because Card has its own default shape CardDefaults.shape. To ensure that the Column inside it respects this shape, you need to clip it accordingly.

Here’s how you can do it:

@Composable
fun PreviewWindow() {
    Card {
        Column(
            modifier = Modifier
                .padding(2.dp)
                .clip(CardDefaults.shape) // Clip the Column to match the Card's shape
                .background(Color.Blue)
                .width(200.dp)
                .aspectRatio(1F)
        ) { }
    }
}

By applying .clip(CardDefaults.shape), the Column will take on the same rounded shape as the Card, ensuring proper clipping.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316315a4568201.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信