android - 如何在 RecyclerView 中的最后一项之后设置恒定边距?
问题描述
last item
我希望在RecyclerView
图像之后有一些空间。
图像不是项目数少的状态,而是大到可以滚动的状态。
换句话说,当滚动到底部时,我希望最后一个项目位于图像的黑条上方。
但我已经实现的是:
正如您在图像中看到的那样,我已经实现的是该项目穿透条形并叠加在底部。
滚动时,栏是否与项目重叠并不重要,但是当滚动到底部时,我希望最后一个项目位于栏的顶部。
添加:
这些回收器视图动态地添加和删除项目。
一次,您只需发布 XML 代码。
如果您需要其他代码,请告诉我。
XML
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:background="@color/transparentBg"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/add_exercise"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="8dp">
<ImageView
android:id="@+id/add_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_add"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/black" />
<TextView
android:id="@+id/add_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="ADD ROUTINE"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_icon" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
解决方案
您可以将 FrameLayout 设置为特定高度,然后将您的 recyclerview 边距底部设置为与框架布局高度相同。
或者您可以将您的 ConstraintLayout 更改为 LinearLayout。
推荐阅读
- css - 如果我添加并使用常规字体,为什么字体系列是粗体?
- amazon-web-services - 通过 ssh 将 EC2 连接到 Git
- python - Python 和 ASP .Net 核心之间的 ConnectionError
- xamarin - 在 Xamarin Mac 桌面应用程序中实现首选项屏幕
- javascript - face-api.js --- 通过网络摄像头识别
- rust - Rust 无法链接
- php - PHP codeigniter if 语句无法正常运行
- php - Laravel 8 和多个可选参数
- ios - 使用 iPhone 时 PeerJS 视频流不起作用 - iOS 到 Android 或 iOS 到 iOS - Node.js
- firefox - PermissionError:[Errno 13] 权限被拒绝:'geckodriver.log'