2

Ich habe eine Aktivität, die ein RecyclerView (gegebenenfalls in einem CardView) und ein FloatingActionButtonRecyclerView mit FloatingActionButton

ich die FAB will immer unten rechts auf dem Bildschirm zu sein, aber wenn ich scrollen bis zum Ende der RecyclerView, der FAB versteckt einen Teil des Inhalts auf dem letzten Element.

Mit android:layout_marginBottom="48dp" auf dem übergeordneten CardView (oder die RecyclerView selbst nach dem Entfernen CardView) behebt dieses Problem, aber es bewirkt, dass die RecyclerView an die Bildschirmgröße minus den 48dp Marge schrumpfen.

Ich möchte die RecyclerView in voller Größe (dh passt für alle Elemente), aber wenn ich über die Elemente blättern, bis ich das letzte Element erreiche, sollte dieser Rand sein, so dass die FAB nicht das letzte Element des abdecken RecyclerView. Das ähnelt dem Verhalten der E-Mail-Liste in der Google Inbox/Google Mail-App.

Ich habe viele Fragen mit ähnlichen (aber nicht gleichen) Problemen gesehen, aber keine der Lösungen hat für mich funktioniert. Ich weiß, dass es eine einfache Lösung für dieses Problem geben sollte, und ich möchte nicht LinearLayoutManager erweitern, wie es für dieses Problem zu viel scheint. Ich möchte auch nicht den FAB auf Scroll verstecken. Hier

ist das, was ich bisher:

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> 

Antwort

8

Entfernen Sie die layout_marginBottom aus dem CardView und fügen Sie den folgenden zum RecyclerView:

android:paddingBottom="48dp" 
android:clipToPadding="false" 
+0

Eigentlich verwende ich 'layout_marginBottom'. 'paddingBottom' stammt aus einem der Versuche. Die Frage wurde aktualisiert. Versuchte Ihren Vorschlag mit und ohne 'layout_marginBottom', aber es fügte nur zusätzlichen Leerraum am Ende des' RecyclerView' hinzu –

+0

Sorry @ A.A. es ist clipToPadding = "false" (nicht "true"). Ich habe meine Antwort bearbeitet. – mVck

+0

Das ist sehr nah an dem, was ich will, aber am Ende der Liste ist immer noch Leerraum. Ich möchte, dass dieser Bereich den Hintergrund des 'CoordinatorLayout' statt –

Verwandte Themen