admin管理员组文章数量:1401673
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 badges1 Answer
Reset to default 1The 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.
本文标签: kotlinHow to clip the content to match to the corner of a Card in ComposeStack Overflow
版权声明:本文标题:kotlin - How to clip the content to match to the corner of a Card in Compose? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744316315a2600282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论