2017-02-10 72 views
1

后我有一些FloatingActionButtons在Android应用,在一个视图,其中按钮下面的内容是可滚动的锚定的标题栏的下方。在初始加载,视图显示正确,就像这样:FloatingActionButton - 不正确的z索引滚动

enter image description here

当用户滚动页面上的内容,他们应该得到的是这样的:

enter image description here

值得注意的是,剩余上面的屏幕上的所有其他内容的按钮。但是什么实际上情况是这样的:

enter image description here

当按钮呈现不正确的标题栏的后面。我的布局XML文件是这样的:

<?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> 

...其中content_event_details布局具有NestedScrollView作为其根元素,它包含地图,详细的文字,并可以在上面的图片可以看到其他用户界面元素(基本上除标题栏和浮动按钮之外的所有内容)。

如何使FloatingActionButtons始终保持在标题栏顶部?

回答

1

海兰Aroth,

在您Appbar,添加机器人:海拔= “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"> 

,并在含有FAB你的LinearLayout, 添加机器人:海拔= “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"> 

希望它有助于:)

+1

安卓setElevation - >安卓海拔 – wrkwrk

+0

完美的作品。尽管@wrkwrk指出,但在XML中使用的正确标签是android:elevation,而不是android:setElevation。 – aroth

+0

Ohhhh我很抱歉 – Ritik