2015-12-29 40 views
3

我正在構建一個包含地圖片段的工具欄。工具欄固定在位置並且不透明。協調器佈局內容顯示在狀態欄後面

每當視圖的內容向上滾動時,地圖片段隨之移動,但它在工具欄上方(因此位於狀態欄本身和狀態欄的橙色背景之間)可見。

這是導致問題: MapFragment overlaps statusbar "background"

如果我滾動多一點,紗幕淡入正常,但爲時已晚。

有沒有一種方法,當它上面的工具欄不繪製內容?或者在AppBarLayout內容前面繪製狀態欄背景的方法?

我已經嘗試在AppBarLayout前面繪製一個視圖(位於狀態欄的右下方),但是一旦MapFragment一直向上滾動,它就會被帶到該視圖的前面,使得MapFragment在小小的瞬間。

<?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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clickable="true" 
    android:fitsSystemWindows="true"> 

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

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/orange" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="?attr/actionBarSize"> 

      <fragment 
       android:id="@+id/map" 
       android:name="com.google.android.gms.maps.SupportMapFragment" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_collapseMode="none" 
       tools:context=".restaurants.stores.StoresFragment" /> 

      <ImageView 
       android:id="@+id/minimizeBtn" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="@dimen/stores_details_minimize_margin" 
       android:clickable="true" 
       android:contentDescription="@null" 
       android:paddingTop="@dimen/status_bar_height" 
       android:src="@drawable/selector_map_minimize_btn" 
       android:visibility="gone" /> 

      <include 
       android:id="@+id/cardDetailsLayout" 
       layout="@layout/store_card_small_detail" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/stores_details_card_height" 
       android:layout_alignParentBottom="true" 
       android:layout_margin="10dp" 
       android:visibility="gone" /> 
     </RelativeLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:minHeight="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

      <com.app.views.FontTextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:ellipsize="end" 
       android:singleLine="true" 
       android:text="@string/store_toolbar_text" 
       android:textColor="@color/white" 
       android:textSize="@dimen/toolbar_text_size" 
       app:font="@string/fontFlamaMedium" /> 
     </android.support.v7.widget.Toolbar> 
    </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

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

編輯: 在佈局XML中的機器人:我RecyclerView相關layout_behavior屬性,但工具欄的內容有正確的行爲,問題是,它是狀態欄下可見,這是我不希望它來。

+0

您的活動主題將android:statusBarColor設置爲透明嗎? – cziemba

+0

[內容後面的CoordinatorLayout AppBarLayout]可能重複(http://stackoverflow.com/questions/32855889/content-behind-coordinatorlayout-appbarlayout) –

+0

@cziemba:是的,我已經嘗試透明和非透明,但結果仍然相同 – jsc

回答

0

從工具欄

android:background="?attr/colorPrimary" 

刪除此屬性,這個屬性添加到CollapsingToolbar

app:contentScrim="?attr/colorPrimary" 

的contentScrim將控制工具欄的顏色,確保顏色只有當背景圖像已經褪去出現out

相關問題