2017-02-10 2 views
1

Ich habe einige FloatingActionButtons in einer Android-App, verankert unterhalb der Titelleiste in einer Ansicht, wo der Inhalt unter den Schaltflächen scrollbar ist. Bei der ersten Last, richtig die Ansicht angezeigt wird, wie folgt aus:FloatingActionButton - Falscher Z-Index nach dem Scrollen

enter image description here

Wenn der Benutzer scrollt der Inhalt auf der Seite, was sie sollte bekommen, so etwas wie das ist:

enter image description here

Bemerkenswert, mit den Tasten bleiben alle anderen Inhalte auf dem Bildschirm. Doch was tatsächlich geschieht, ist dies:

enter image description here

Wo die Tasten nicht richtig hinter der Titelleiste gemacht. Mein Layout XML-Datei sieht wie folgt aus:

<?xml version="1.0" encoding="utf-8"?> 
<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:fitsSystemWindows="true" 
    tools:context="au.com.suncoastpc.coastlive.activity.EventDetailsActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/app_bar_height" 
     android:fitsSystemWindows="true" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/toolbar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

    <LinearLayout 
     app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 


     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab_facebook" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/fab_margin" 
      android:layout_marginBottom="@dimen/fab_margin" 
      app:backgroundTint="#3c5a99" 
      app:srcCompat="@drawable/icon_facebook"/> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab_music" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/fab_margin" 
      android:layout_marginBottom="@dimen/fab_margin" 
      android:layout_marginLeft="@dimen/fab_margin" 
      app:backgroundTint="#008800" 
      app:srcCompat="@drawable/icon_music"/> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/fab_margin" 
      app:backgroundTint="#880000" 
      app:srcCompat="@drawable/icon_info"/> 
    </LinearLayout> 

    <include layout="@layout/content_event_details"/> 
</android.support.design.widget.CoordinatorLayout> 

... wo die content_event_details Layout ein NestedScrollView als Wurzelelement und enthält die Karte, Details Text und andere UI-Elemente, die oben in den Bildern zu sehen ist (im Grunde alles außer der Titelleiste und schwebenden Tasten).

Wie kann ich die FloatingActionButtons immer oben auf der Titelleiste bleiben?

Antwort

1

Hy Aroth,

In You AppBar, fügen android: Höhe = "4DP" >>>

<android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/app_bar_height" 
     android:fitsSystemWindows="true" 
     android:elevation="4dp" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

und in Ihrem Linearlayout FAB enthält, hinzufügen android: Höhe = "6DP" >>>

<LinearLayout 
     app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:elevation="6dp"> 

hoffen, es hilft :)

+1

android: setElevation -> android: höhe – wrkwrk

+0

Funktioniert perfekt. Wie in @wrkwrk angemerkt, ist das korrekte Tag, das im XML verwendet werden soll, "android: elevation", "not_' android: setElevation ". – aroth

+0

Ohhhh Entschuldigung dafür – Ritik

Verwandte Themen