繁体   English   中英

Android 粘性 - 使用 jetpack 组合的页脚:将页脚视图与表格对齐,直到达到屏幕大小,然后固定在底部

[英]Android sticky - footer using jetpack compose: Align footer view to table, until it reaches screen size and then become fixed at the bottom

我想使用 jetpack compose 来实现这一点。

在此处输入图像描述

A是行项目的可滚动列表。 A小于屏幕(或父)大小时, B (页脚)应放在最后一行的下方。 A + B大于屏幕尺寸时, B固定在底部, A内容可滚动。 我想知道是否有简单的方法来实现这一点,使用 compose ConstraintLayout。

我找到了解决方案。 我不得不在 A 使用Modifier.weight(1f, false)

有很多方法可以做到这一点,但最有效的方法是使用Scaffold View 的bottomBar属性。

例如:

@Composable
fun RenderContent() {
    Scaffold(
        topBar = { /* Your app bar goes here */ },
        bottomBar = { /* Anything you place in here will be stick to the bottom. */ }
    ) {
        // ... Rest of the content
        // Benefits: If you make the content scrollable and
        // the `bottomBar` composable remain on top of the content
    }
}

如果我理解正确,您正在尝试向 LazyColmn 添加页脚视图。 JetpackCompose 中的 LazyColumn 的行为类似于原生 ListView。 我将举一个 LazyColumn 的示例,该示例在底部有一个视图(可组合),当您在列表末尾滚动时会显示该视图:

LazyColumn() {
item {
    //If you want the first item to stay always on top as you scroll use stickyHeader for this section.
    Text("This is the first item")
}
items(listItems.size) {
    Text("This is a normal list item")
}
item {
    Text("This item will behave as a footer and display at the end of the list")
}

}

希望这可以帮助某人。 谢谢

暂无
暂无

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

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