ViewPager in a NestedScrollView

前端 未结 19 2147
面向向阳花
面向向阳花 2020-11-27 10:08

I need to create an interface like Google Newsstand which is a sort of ViewPager (horizontal scroll) over a collapsing header (vertical scroll). One of my requirements is to

19条回答
  •  悲哀的现实
    2020-11-27 10:26

    Instead of placing ViewPager inside the NestedScrollView, do it the other way around.

    Place the NestedScrollView in the child Views inside the ViewPager which in essence is the Fragment's layout. It's also very likely that you won't even need to use NestedScrollView if your Fragment's list layout is very simple.

    Example Layouts

    Activity's Layout:

    
    
    
        
    
            
    
                
    
                
    
            
    
        
    
        
    
            
    
            
        
    
    
    

    If you don't need the TabLayout, you can ditch the LinearLayout and make ViewPager standalone. But be sure to use app:layout_behavior="@string/appbar_scrolling_view_behavior" in ViewPager attributes.

    Simple Fragment's Layout:

    
    
    

    Complex Fragment's Layout:

    
    
        
            
            
        
    
    

    Example App: CollapsingToolbarPoc

提交回复
热议问题