简体   繁体   English

LazyColumn 中隐藏的底部项目 - Jetpack Compose

[英]Hidden bottom item in LazyColumn - Jetpack Compose

I am trying to create a list of items with a hidden button at the bottom.我正在尝试创建一个底部带有隐藏按钮的项目列表。 By default the button is not visible on the screen.默认情况下,该按钮在屏幕上不可见。

If a user scrolls to the bottom of the list the button should appear like it is the last item of the list.如果用户滚动到列表的底部,则该按钮应显示为列表的最后一项。

I created illustrations to better visualize the desired behaviour:我创建了插图以更好地可视化所需的行为:

Sketch 1: List with a few items草图 1:列出一些项目

在此处输入图像描述

Sketch 2: List with a lot of items草图 2:包含很多项目的列表

在此处输入图像描述

I already tried the solution for a similar problem ( https://stackoverflow.com/a/69196765/11720296 ) and added extra offset but unfortunately it didn't work.我已经尝试了类似问题的解决方案( https://stackoverflow.com/a/69196765/11720296 )并添加了额外的偏移量,但不幸的是它没有用。

Does somebody have an idea how to create this behaviour?有人知道如何创建这种行为吗?

itemsIndexed will help in this case in following example I have used itemsIndexed in Lazycolumn it gives index which is visible to the user.在下面的示例中,itemsIndexed 将有所帮助,我在 Lazycolumn 中使用了 itemsIndexed,它提供了对用户可见的索引。 In this example I was trying to show some specific text only when first message is visible.在这个例子中,我试图仅在第一条消息可见时才显示一些特定的文本。

 LazyColumn() {
                itemsIndexed(tempListOfMessages) { index, localMessage ->
                    if (localMessage != null) {
                        SingleMessageView(
                            localMessageInfo = localMessage,
                            (index == 0)
                      )
                    }
                }  
            }

在此处输入图像描述

when scroll that text scroll with first item.当滚动该文本与第一项滚动。

在此处输入图像描述

Try this.尝试这个。

Scaffold { paddingValues ->
LazyColumn(
    modifier = Modifier.fillMaxSize(),
    contentPadding = paddingValues
) {
  ...
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM