簡體   English   中英

Jetpack Compose - 如何根據另一個組件的高度調整填充?

[英]Jetpack Compose - how to adjust the padding depending on the height of another component?

我有一個使用Modifier.wrapContentHeight()設置的組件,其高度根據其內容具有不同的高度。 我想動態地將其他組件的填充調整到第一個組件的高度。 我試過這樣的事情:

       var height = 0
       val resourceContentBottomPadding = height + 16

       LazyColumn(
            modifier = Modifier.fillMaxSize(),
            contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = height.dp),
        ) { /.../ }

       Column(
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
                .onGloballyPositioned {
                    height = it.size.height
                }
        ) {
            if (something)
                SomeComposeElement()

            Button()
        }

不幸的是,它沒有任何改變。

如果您將 LazyColumn 和 Column 放在祖先 Column 中並為您的 LazyColumn 設置modifier = Modifier.fillMaxWidth().weight(1f)它只會在 Column 布局后占用空間,即總高度 - 列的高度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM