【发布时间】:2020-05-30 14:45:51
【问题描述】:
我想在 recyclerView 列表的末尾添加一个简单的 TextView 以帮助用户,以防他找不到他正在寻找的项目。但是,就像 android 上的所有东西一样,没有什么是简单的,文档也毫无价值。
请注意,我不想通过此处建议的 Recyclerview 适配器操作来实现此目的:
How to add a button at the end of RecyclerView?
我尝试了很多选项并在谷歌上阅读。以下是我最后一次尝试
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
tools:context=".collaborate.CollaborateActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<include
android:id="@+id/collaborate_toolbar"
layout="@layout/toolbar" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/collaborate_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="80dp"
android:clipToPadding="false"
android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"
tools:listitem="@layout/list_collaborate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Didn't find what you were looking for? try...."/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/collaborate_fb_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:layout_marginEnd="8dp"
android:src="@drawable/check" />
</com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout>
【问题讨论】:
-
您链接的问题正是您需要的解决方案。它有什么问题?
-
首先,这样的操作并不是做这么基本的事情的最佳实践。我就是无法接受。其次,我正在使用无法实现的 FirestoreRecyclerAdapter。为什么 NestedScrollView 不起作用?它不应该这样做吗?我用错了吗?
-
同意@Nicolas。这几乎是您链接的问题的确切实现:stackoverflow.com/a/38691600/7210237
-
“这样的操作不是做这么基本的事情的最佳实践。我就是不能接受。”欢迎来到 android 开发 :) 如果你使用 NestedScrollView,你的 RecyclerView 不会回收任何东西,因为 RecyclerView 的高度不是固定的。我不了解 FirestoreRecyclerAdapter,所以我无法真正帮助您。
-
@Ran,这里有一个例子,基于 Kotlin,官方:codelabs.developers.google.com/codelabs/… 有点太长了,但是解决方法差不多。在 Android 中,没有
addFooter函数可以简单地捕捉列表下的视图。
标签: android android-recyclerview android-nestedscrollview