小编Cod*_*ile的帖子

循环中的每个元素都应填充行中可用的所有可用空间

我有循环遍历的元素,单击的元素将背景更改为绿色。我希望每个元素都填充行中可用的所有可用空间。但是,如果我提供,weight(1f)它只显示一个占据所有空间的元素,但应该有三个元素或我从外部传递的任何元素数。

在此输入图像描述

@Composable
fun BottomMenu(
    items: List<BottomMenuContent>,
    modifier: Modifier = Modifier,
    activeHighlightColor: Color = Green,
    activeTextColor: Color = Color.White,
    inactiveTextColor: Color = Color.Black,
    initialSelectedItemIndex: Int = 0
) {
    var selectedItemIndex by remember {
        mutableStateOf(initialSelectedItemIndex)
    }
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = modifier
            .fillMaxWidth()
            .background(Gray)
            .padding(4.dp)


    ) {
            items.forEachIndexed { index, item ->
                BottomMenuItem(
                    item = item,
                    isSelected = index == selectedItemIndex,
                    activeHighlightColor = activeHighlightColor,
                    activeTextColor = activeTextColor,
                    inactiveTextColor = inactiveTextColor
                ) {
                    selectedItemIndex = index
                }
        }

        } …
Run Code Online (Sandbox Code Playgroud)

kotlin android-jetpack-compose

5
推荐指数
1
解决办法
189
查看次数

标签 统计

android-jetpack-compose ×1

kotlin ×1