【问题标题】:Jetpack compose: elevate card from bottomJetpack compose:从底部提升卡片
【发布时间】:2022-12-19 00:44:46
【问题描述】:

当我遇到这个问题时,我正在 Jetpack Compose 中实施 Card 形状。

我想要的只是提升卡的一端或底部,但我没有找到任何相关文件来支持这一点。
我试着查看Card的实现代码来了解一下(以下是实现代码):

@Composable
fun Surface(
    modifier: Modifier = Modifier,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colors.surface,
    contentColor: Color = contentColorFor(color),
    border: BorderStroke? = null,
    elevation: Dp = 0.dp,
    content: @Composable () -> Unit
) {
    Surface(
        modifier = modifier,
        shape = shape,
        color = color,
        contentColor = contentColor,
        border = border,
        elevation = elevation,
        content = content,
        clickAndSemanticsModifier = Modifier
            .semantics(mergeDescendants = false) {}
            .pointerInput(Unit) { }
    )
}

但这里它在Dp中接受elevation,这意味着它提升了整个Card。

所以我不知道如何在Jetpack Compose实现它,有人可以帮我实现吗?

编辑:

我为这个问题创建了一个问题:https://issuetracker.google.com/issues/227767373

【问题讨论】:

  • 到目前为止,影子修改非常有限,this 功能请求是投票最多的 Compose 问题

标签: android android-jetpack-compose android-cardview material-components-android


【解决方案1】:

你可以像这样抬高整个底部

@Composable
fun BottomWithShadow(
    content: @Composable ColumnScope.() -> Unit
) {
    Box {
        Card(
            shape = RoundedCornerShape(
                topEnd = 0.dp,
                topStart = 0.dp,
                bottomEnd = 0.dp,
                bottomStart = 0.dp),
            modifier = Modifier
                .fillMaxWidth()
                .height(50.dp)
                .align(Alignment.BottomCenter),
            elevation = 10.dp
        ) {}
        Column(
            modifier = Modifier
                .clip(
                    RoundedCornerShape(
                        topEnd = 0.dp,
                        topStart = 0.dp,
                        bottomEnd = 0.dp,
                        bottomStart = 0.dp)
                )
                .background(color = Color.White),
            content = content
        )
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2021-11-07
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多