2017-05-06 11 views
0

大きなヘッダーイメージを含む折りたたみツールバーを実装しようとしています。私はイメージが非常に大きく(そして動作する)、完全に崩壊しないようにしたい(それもうまくいく)。問題は、ツールバーが折りたたみ可能な最小の高さに達すると、画像が消え、アプリの主な色にフェードすることです。 崩壊しても画像が見えるようにしたい。折りたたみスクロールアップ時にツールバーの画像が消える

また、戻るボタンが画像とともに拡大表示されていて、固定しておく必要があります。

活動のXML:

<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/app_bar_layout" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
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:fitsSystemWindows="true" 
    app:contentScrim="?attr/colorPrimary" 
    app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

    <ImageView 
     android:id="@+id/imageViewToolbar" 
     android:minHeight="500dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:scaleType="centerCrop" 
     app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 
     app:layout_collapseMode="parallax" /> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:title="" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     app:layout_scrollFlags="scroll|enterAlways" 
     /> 
</android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 
<include layout="@layout/detail_content"/> 

感謝。

答えて

1

使用このコード:

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

     <ImageView 
      android:id="@+id/bgheader" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:fitsSystemWindows="true" 
      android:background="@drawable/sunflowerpic" 
      app:layout_collapseMode="pin" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/MyToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="parallax" /> 

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

ここで、出力がどのように見えるか、スクロールアップした後。画像は、appbarの背景として上部に固定されます。ここで

enter image description here

私はそれを固定グッドExample

+0

これで修正されませんでした。私はこのように編集しました:https://pastebin.com/DCVHF6Mh – user11230

1

です:

私はイメージがCollapsingToolbarLayoutにapp:statusBarScrim="@android:color/transparent"をadddingことにより、固体の色にフェードしないようにと私はスライドバックボタンを固定ツールバーのレイアウトにapp:layout_collapseMode="pin"を追加します。

関連する問題