How to sync scroll of two CoordinatorLayout + AppBarLayout

后端 未结 2 2088
北海茫月
北海茫月 2020-12-31 14:32

I have an activity with XML.

Something like:




        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 14:51

    How can I sync scroll of these 2 AppBarLayouts so that the outer appbar collapses either before/after (doesn't matter if it happens before or after) the inside appbar collapses?

    Delete that Fragment's CoordinatorLayout and just use RelativeLayout as a root tag (for Fragment)and then do your stuffs with that ViewPager in the MainActivity.

    For example, use it inside that CoordinatorLayout like this:

    
    
        
        
        
    
    

    Github example:

    https://github.com/TheLittleNaruto/SupportDesignExample

    Or perhaps you want to scroll that ViewPager inside the NestedScrollView but, you'll face a problem then use the following code inside it:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    That's pretty much it.

    A fragment of the ViewPager has a CoordinatorLayout and AppBarLayout+CollapsingToolbarLayout. XML:

    You don't need to use them twice.

提交回复
热议问题