CoordinatorLayout with RecyclerView And Collapsing header

后端 未结 2 693
南方客
南方客 2020-12-22 20:28

I have a layout like the following:

(Toolbar, Header View, Text View, RecyclerView)

I need the header to be collapsed when I scrolling recyclerview\

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 20:58

    You can achieve it by having this layout:

    
    
        
    
            
    
                
                
                    .....
                
    
                
    
            
    
           
        
    
        
    
    
    

    You pin your toolbar by having the app:layout_collapseMode="pin" property set. You make RecyclerView properly scrollable by setting app:layout_behavior="@string/appbar_scrolling_view_behavior" and that's pretty much it.

    NB! Position of "Choose item" TextView depends on the particular behaviour you want to achieve:

    • you can include it as a first element of your RecyclerView's Adapter to scroll it away, once user start scrolling through the RecyclerView;
    • you can add it into AppBarLayout so it will always stick on top of the RecyclerView, whenever you scroll it or not;

    You can read more here Android Design Support Library and here Design Support Library (III): Coordinator Layout

    I hope, it helps!

提交回复
热议问题