0
Follow
0
View

CollapsingToolbar with second toolbar instead of ImageView

jmshxy5233 注册会员
2023-01-25 08:48

You could wrap the CoordinatorLayout into a another ViewGroup and add the main Toolbar into this new root layout instead. This will avoid the confusion of the app:layout_collapseMode="pin" to the main toolbar.

So now the entire layout hierarchy would be:


    
          <<<<<<<<<<<<<<<<<<< main toolbar
    
    
        
             
                  <<<<<<<<<<<<<<<<<<< second toolbar
        
            

Then to fix the collapsing behavior like you want you need to change the scrolling flags of the CollapsingToolbarLayout to "scroll|enterAlways" instead of "scroll|exitUntilCollapsed". This will make the toolBar off the top screen.

And build the layout of the second Toolbar with a normal ViewGroup inside of it; here I'm using ConstraintLayout:


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

    



















About the Author

Question Info

Publish Time
2023-01-25 08:48
Update Time
2023-01-25 08:48