我有了一個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'的背景,而不是 –