Is there a way to add a simple header/footer to a RecyclerView?

Here you can see what I've got. The first Card touches the Toolbar This is what I've got

And here you can see what I want. 8dp Padding between the bottom and the Card. This is what I want to have

到目前为止我try 过的方法:

  • 在我的回收视图中使用标题视图.但我认为,对每一位回收者来说,这样做是非常不够的.

  • 使用8dp上边距,这会导致在滚动时,recyclerview的上/下有白色条.

  • 向列表项添加填充,这会导致外卡和内卡之间的边距不同.

  • 我相信有一个简单的解决方案,我目前还不知道.

    推荐答案

    添加一个顶部填充并将clipToPadding设置为false就可以了

      <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:paddingTop="8dp"
        android:clipToPadding="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    Android相关问答推荐

    Health Connect(Android 14):需要更新应用程序才能继续与Health Connect同步

    LaunchedEffect何时捕获值?

    RippleTheme在作曲material 1.7.0中被废弃

    如何使用Gradle风味在两个Kotlin导入(Google vs Amazon Java billing library)之间进行 Select ?

    有人能帮我在应用程序上使用模拟位置时避免被发现吗?我已经反编译并粘贴了一个代码,S小文件

    如何阻止Gradle在编译时生成app-metadata.properties

    不能在LazyGrid-Jetpack Compose中使用填充最大宽度或填充父项最大宽度

    如果我的圆形图像的顶部居中于卡片内部,我如何在其下方画一条弧线?

    如何在Jetpack Compose android中使用导航

    我需要在房间数据库中保留旧的自动迁移行吗?

    错误:参数的类型必须是用@Entity注释的类或其集合/array. java.lang.String tocd);

    Android 访问任意公共目录

    如何仅使用您的 Android 应用程序定位平板电脑?

    未找到 com.android.tools.build:gradle:7.4.0 的匹配变体

    在 Jetpack Compose 中包装内容

    在 Jetpack Compose 中清除列表时可组合不重组

    如何在jetpack compose中通过lamda返回columnScope/RowScope

    MediumTopAppBar Material3 只更改大标题

    插入查询室 OnConflictStrategy.REPLACE

    无法使用 Gradle 托管设备对基线配置文件运行测试