ViewPager in a NestedScrollView

前端 未结 19 2126
面向向阳花
面向向阳花 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:36

    I was having a similar problem (but without CollapsingToolbarLayout, just a simple Toolbar + TabLayout within the AppBarLayout). I wanted the Toolbar to scroll out of sight when scrolling down the contents of a ViewPager within the NestedScrollView.

    My layout went something like this:

    
    
            
    
                
    
                
             
    
             
    
                    
                    
             
    
    
    

    This layout wasn't working as intended, but I solved it by simply getting rid of the NestedScrollView and using a LinearLayout instead. It worked for me right away on Android Support Library v23.1.0. Here's how the layout ended up:

    
    
            
    
                
    
                
             
    
             
    
                    
                    
             
    
    
    

    PS: These were actually two layout files in my project. I copied and pasted them here and tried to structure them as it would look like in a single file. I'm sorry if I screwed up while copy-pasting but please let me know if that's the case so I can fix it.

提交回复
热议问题