我想像这样吵架

Expected Output

enter image description here

enter image description here

我试过这段代码

DividerWithItem

@Composable
fun DividerWithItem(
    modifier: Modifier = Modifier,
    index: () -> Int,
    itemName: String,
    lastIndex: () -> Int,
    moreRowContent: @Composable RowScope.() -> Unit,
) {
    Column {
        if (index() == 0) {
            Divider(color = Cloudy, thickness = dimensionResource(R.dimen.separator_height_width))
        }
        Row(
            modifier = modifier,
            horizontalArrangement = Arrangement.spacedBy(4.dp),
            verticalAlignment = Alignment.CenterVertically,
        ) {
            Text(
                text = itemName,
                modifier = Modifier.padding(vertical = 12.dp),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis
            )
            moreRowContent()
        }
        if (index() <= lastIndex()) {
            Divider(color = Cloudy, thickness = 1.dp)
        }
    }
}

BpmOptionsLabel

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun LazyItemScope.BpmOptionsLabel(
    index: () -> Int,
    optionName: String,
    lastIndex: () -> Int
) {
    DividerWithItem(
        modifier = Modifier
            .fillMaxSize()
            .animateItemPlacement(),
        index = index,
        itemName = optionName,
        lastIndex = lastIndex
    ) {
        Image(
            modifier = Modifier.weight(.3f),
            painter = painterResource(R.drawable.ic_menu),
            contentDescription = null,
        )
    }
}

BpmOptionsLabelPreview

@Preview(showBackground = true)
@Composable
fun BpmOptionsLabelPreview() {
    LazyColumn {
        item {
            BpmOptionsLabel(
                index = { 0 },
                "Item item item item item m 1",
                lastIndex = { 1 }
            )
        }
    }
}

Actual Output

enter image description here

唯一的问题是TextImage项不在适当的位置

推荐答案

DividerWithItem中,将weight(1f)应用到Text

Text(
    text = itemName,
    modifier = Modifier.padding(vertical = 12.dp).weight(1f),
    maxLines = 1,
    overflow = TextOverflow.Ellipsis
)
moreRowContent()

并在LazyItemScope.BpmOptionsLabel中从Image中删除weight修饰符:

Image(
    //modifier = Modifier.weight(.3f),
    painter = painterResource(R.drawable.ic_menu_gallery),
    contentDescription = null
)
    

enter image description here

如果要增加图像占用的空间,请使用padding修改器:

Image(
    //...
    modifier = Modifier.padding(horizontal = 20.dp)
)

enter image description here

Android相关问答推荐

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

在Jetpack Compose中,material 3 Textfield上的底部边框 colored颜色 是如何更改的?

这款应用与最新版本的Android不兼容.在Android 14中

穿戴与iPhone连接的安卓操作系统

Modifer.Align()不适用于行/列/框中的文本.未解决的作用域实例错误

如何防止在Android Studio中设置kotlin断点时优化变量

android crashlytics 显示崩溃但不显示我的课程中的位置

AndroidX Media3 迁移指南

在 kotlin 协同 routine 中,如何将数据范围限定为请求路径(以 MDC 为例)?

如何在 Jetpack Compose 中处理水平滚动手势和变换手势

如何删除 Jetpack Compose 中按钮的左边框?

Android Studio:按下前缀键:切换 Logcat 格式

Electric Eel 后 Gradle 项目同步失败 | 2022.1.1更新

如何使用 Jetpack Compose 制作两个圆圈

无法解析依赖项'com.github.smarteist:autoimageslider:1.4.0-appcompat'

Kotlin 调用带参数的函数 Any is xxx ||任何 yyy 都不起作用

Android Studio Emulator Internet 连接问题仅是第一次

如何在 TextInputEdit 中调整可绘制对象的大小

操作系统会终止已启动的服务并调用Service.onDestroy吗?

为什么使用 React Native 和 expo 创建的 APK 体积这么大?