2016-09-25 97 views
1

我試圖在摺疊工具欄中將狀態欄背後的圖像視圖,並嘗試了很多解決方案,它在狀態欄後面,但在狀態欄下方開始說明它,但在滾動它後面。我怎樣才能解決這個問題,這裏是XML文件(它是一個活動中的片段)ImageView不會在摺疊工具欄中的狀態欄後面

片段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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/fragment_detail_app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="240dp" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/fragment_detail_collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:statusBarScrim="@android:color/transparent" 
      app:theme="@style/Theme.AppCompat.NoActionBar"> 

      <com.android.volley.toolbox.NetworkImageView 
       android:id="@+id/fragment_detail_collapsing_toolbar_image_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" 
       app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/fragment_detail_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="120dp" 
       app:layout_collapseMode="pin" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:titleTextColor="@android:color/white"> 
      </android.support.v7.widget.Toolbar> 

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

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

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

    <com.android.volley.toolbox.NetworkImageView 
     android:id="@+id/fragment_detail_anchor_image" 
     android:layout_width="96dp" 
     android:layout_height="144dp" 
     android:layout_margin="40dp" 
     android:background="@android:color/white" 
     app:layout_anchor="@id/fragment_detail_app_bar_layout" 
     app:layout_anchorGravity="bottom" 
     android:scaleType="fitXY" 
     android:elevation="8dp"/> 
</android.support.design.widget.CoordinatorLayout> 

活動XML:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/movie_detail_fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="false" 
    tools:context="app.com.thetechnocafe.moviesnow.MovieDetailActivity"> 

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

SCREENSHOT

+0

見http://stackoverflow.com/questions/33668668/coordinatorlayout-not-drawing-behind-status-bar-even-with-windowtranslucentstatu – Philipp

回答

2

把它解決了。來自網絡的圖像具有不同的比例,我發現的一件事是,如果圖像不適合狀態欄後面的資源,它會自動適應狀態欄。我只需要在NetworkImageView中設置android:scaleY="1.2"將其推入狀態欄。

+0

真棒馬恩,幫助了很多。 –

0

在使用API​​ 21+的設備可以使用使狀態欄變爲半透明的自定義主題。

<style name="AppTheme.NoActionBar.NoStatusBar"> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

這種風格在你AndroidManifest.xml添加到文件夾values-v21內並設置Activty主題是這樣的:

<activity 
    android:name=".activity.AboutActivity" 
    android:theme="@style/AppTheme.NoActionBar.NoStatusBar" /> 

還有一件事。我認爲您還需要將android:fitsSystemWindows="true"添加到NetworkImageView

+0

試過,但它不工作 –

+0

什麼API級別是設備或你正在測試的仿真器?你能發佈清單和樣式文件嗎? – rubenlop

+0

23級,摩托x風格 –