【问题标题】:Stretch the surface along the entire height which is in row沿行中的整个高度拉伸表面
【发布时间】:2022-08-18 19:02:37
【问题描述】:

我有一个惰性列,其中有一个卡片列表,其中有一行和两列,第一列的高度比第二列大得多。第二列具有使用表面制作的具有不同背景的文本。 fillMaxHeight 修饰符不起作用。已经尝试通过其他方式做到这一点: 1)

Row(
                modifier = Modifier
                    .height(IntrinsicSize.Min)

但是,有一个问题,这只适用于静态组件,而且这是我的专栏中的一条懒惰行,并且组合开始崩溃 2)以这种方式获取高度。

//Save height
 val heightIs = remember {
            mutableStateOf(0.dp)
        }
//Get the context
val localDensity = LocalDensity.current

Column(modifier = Modifier.fillMaxWidth(0.7f).onSizeChanged{cord->
                    heightIs.value = with(localDensity){
                         cord.height.toDp()
                    }

这个解决方案的问题是,当没有lazyrow时,它不能正确分配高度。

  • 目前尚不清楚您要达到的目标。你想要两列高度相同吗?

标签: android-jetpack-compose


【解决方案1】:

您必须将修饰符height(IntrinsicSize.Min) 应用于RowfillMaxHeight() 应用于第二个Column

就像是:

LazyColumn(
    modifier = Modifier.fillMaxSize()
) {
    itemsIndexed(itemsList) { index, item ->

        Row(Modifier.height(IntrinsicSize.Min)) {

            Column(Modifier.fillMaxWidth(0.5f)) {
                Box(Modifier.fillMaxWidth().height(100.dp*index).background(Blue))
            }

            Column(Modifier.fillMaxWidth().fillMaxHeight()) {

                Surface(Modifier.fillMaxSize(),
                    color = Red) {
                    Text("Text value")
                }
            }

        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-12-23
    • 1970-01-01
    • 2022-01-12
    • 2010-10-17
    • 1970-01-01
    • 2020-03-17
    • 2014-10-14
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多