13

Ich habe gerade die neue Support Design Library mit CoordinatorLayout ausprobiert, aber ich habe Probleme beim Verankern von Kindansichten. Mein Layout sieht derzeit wie folgt aus:CoordinatorLayout layout_anchor funktioniert nicht

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/coordinator_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <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/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="enterAlways" /> 

</android.support.design.widget.AppBarLayout> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_anchor="@id/toolbar" 
    app:layout_anchorGravity="bottom"/> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="16dp" 
    android:layout_marginEnd="16dp" 
    android:layout_marginRight="16dp" 
    android:src="@drawable/ic_fab_add" 
    android:onClick="onAddPlayerClick" 
    android:layout_gravity="bottom|end" 
    app:elevation="4dp" 
    app:borderWidth="0dp"/> 

Wenn die RecyclerView Liste geladen wird, wird der erste Punkt von der Aktionsleiste überlappen. Ich nehme die App an: layout_anchor funktioniert nicht richtig. Ich habe bereits versucht, es zu verankern, um keinen Erfolg zu haben.

Weiß jemand, was ich hier falsch mache?

Antwort

20

Versuchen Sie diesen Code. Sie müssen app:layout_behavior in Ihren RecyclerView

<android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_marginBottom="16dp" 
    android:layout_marginEnd="16dp" 
    android:layout_marginRight="16dp" 
    android:src="@drawable/ic_fab_add" 
    android:onClick="onAddPlayerClick" 
    app:elevation="4dp" 
    app:borderWidth="0dp" 
    app:layout_anchor="@id/appbar" 
    app:layout_anchorGravity="bottom|right|end" 
    android:clickable="true"/> 
+0

Ah verwenden habe ich das wirklich vermissen? ... Danke sehr much.Problem gelöst. –

+0

Welchen Wert hat '@ string/appbar_scrolling_view_behavior' und warum funktioniert das Hinzufügen dieses Verhaltens? – AdamMc331

+0

Ich möchte dies auch wissen – Eenvincible