【问题标题】:Gravity of elements within Row (Jetpack Compose)行内元素的重力(Jetpack Compose)
【发布时间】:2021-09-12 06:41:24
【问题描述】:

如何设置 Row 中元素的重力? 我的行中有两个图像组合。我希望第一个图像位于行的开头,下一个元素位于行的末尾。

我已经尝试过:

Row(Modifier.fillMaxWidth()) {

    Image(
        painter = painterResource(id = R.drawable.logo_voodlee),
        contentDescription = "logo",
        modifier = Modifier
            .width(with(LocalDensity.current) { dimensionResource(id = R.dimen._100sdp) })
            .height(with(LocalDensity.current) { dimensionResource(id = R.dimen._55sdp) })
            .offset(x = with(LocalDensity.current) { dimensionResource(id = R.dimen._16sdp) }),
    )

    Image(
        painter = painterResource(id = R.drawable.ic_menu),
        contentDescription = "logo",
        modifier = Modifier
            .width(with(LocalDensity.current) { dimensionResource(id = R.dimen._19sdp) })
            .height(with(LocalDensity.current) { dimensionResource(id = R.dimen._19sdp) })
        ,
    alignment = CenterEnd //This is not working
    )
}

但它不起作用。

【问题讨论】:

    标签: android alignment row android-jetpack-compose


    【解决方案1】:

    您可以在RowArrangement.SpaceBetween申请

    Row(
        Modifier.fillMaxWidth(),
        horizontalArrangement = Arrangement.SpaceBetween
    ) {
        /* ... */
        Box(Modifier.width(50.dp).height(50.dp).background(Red))
        Box(Modifier.width(50.dp).height(50.dp).background(Blue))
    }
    

    【讨论】:

    • 我想要另一个元素就在最后一个元素的左边。我该怎么做?
    • 对最后 2 个元素使用单独的行(在父行内)。想知道是否有更好的方法来做到这一点。
    • @SparshDutta 使用 constraintlayout 或只是另一个 Row 作为父 Row 内的第二个元素
    猜你喜欢
    • 1970-01-01
    • 2022-12-12
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    相关资源
    最近更新 更多