我有了一个RecyclerView
(任选在CardView
)我想FAB是始终在屏幕右下角的活动和FloatingActionButton
RecyclerView与FloatingActionButton
,但是当我滚动的结束RecyclerView
,FAB隐藏了最后一项内容的一部分。
父CardView
(或移除CardView
后RecyclerView
本身)使用android:layout_marginBottom="48dp"
解决了问题,但它会导致RecyclerView
缩小到屏幕大小减去48dp
保证金。
我希望RecyclerView
为全尺寸(即适合所有项目),但是当我滚动项目直到达到最后一个项目时,应该有该边距,以便FAB不会覆盖最后一项RecyclerView
。这与Google Inbox/Gmail应用中电子邮件列表的行为类似。
我见过很多类似(但不是相同)问题的问题,但没有解决方案为我工作。我知道这个问题应该有一些简单的解决方法,我不想延长LinearLayoutManager
,因为这个问题似乎太多了。我也不想在滚动中隐藏FAB。
这是我到目前为止有:
activity_main.xml中
<android.support.design.widget.CoordinatorLayout
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:background="@color/colorBackground"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/card_list"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:onClick="onClick"
app:srcCompat="@drawable/ic_add"/>
</android.support.design.widget.CoordinatorLayout>
card_list.xml
<android.support.v7.widget.CardView
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:layout_marginTop="@dimen/activity_vertical_margin"
android:background="@android:color/white"
android:layout_marginBottom="48dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
其实,我正在使用'layout_marginBottom'。 'paddingBottom'来自其中一项试验。更新了问题。尝试了使用或不使用'layout_marginBottom'的建议,但它只在'RecyclerView'的末尾添加了额外的空白空间。 –
对不起@ A.A。它的clipToPadding =“false”(而不是“真”)。我编辑了我的答案。 – mVck
这与我想要的非常接近,但列表末尾仍有空白。我希望这个空间显示'CoordinatorLayout'的背景,而不是 –