3

現在、CollapsingToolbarLayoutの主な問題は、私が試していることは何でも、ツールバーのminHeight属性は効果がありません。CollapseingToolbarLayoutでminHeightを設定しても効果がありません

私の望ましい結果は、このようになります:

enter image description here

(崩壊または上に留まるいずれかのタイトルながら、特定の拡張高さと例示180dpで一定折りたたま高さ()とCollapsingToolbarLayout)

私が何をするにしても、タイトルが中央にある場合もあれば、完全に崩壊しない場合や、minHeightが無視される場合もあります。 AppBarLayout、CollapsingToolbarLayout、ツールバーそのもの、コンテンツなどのminHeightを設定しようとしましたが、Web上にあるさまざまなアプローチもありますが運がありません。私は、これは私の問題を説明するのに十分な内容であると思います

<android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:minHeight="180dp"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      app:contentScrim="@android:color/transparent" 
      app:expandedTitleGravity="bottom" 
      app:expandedTitleTextAppearance="@style/TextAppearence.App.ToolbarTitle" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:statusBarScrim="@android:color/transparent"> 

      <com.xxxxxx.custom.Banner 
       android:id="@+id/parallax_image" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:adjustViewBounds="true" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/xxxxxxxx" 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0.6" 
       app:layout_scrollFlags="scroll" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:minHeight="180dp" 
       app:layout_collapseMode="pin" /> 

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

は、ここで基本的なXMLです。 ご協力いただきありがとうございます!

答えて

2

minHeightを使用する代わりに、高さを180dpに設定してから、TextViewをツールバーに追加してタイトルとして使用できます。

+0

カスタムTextViewをタイトルとして追加することで、いくつかの調整ができました。とにかくツールバーを展開または折りたたんで作業することはできませんでした。 – TheWhiteLlama

4

これはかなり簡単です。 Toolbarの下余白を折りたたんだバージョンで予約するスペースに設定してください。

これの背後にある理由は簡単です。 CollapsingToolbarLayoutは、画像をお互いに積み重ねるFrameLayoutから継承しています。折りたたまれた範囲を考慮する場合、ツールバーの高さとその上下のマージンだけが考慮されます。

+0

魅力のように働いて、余分な時間をいただきありがとうございました。 – Alessio

関連する問題