How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

后端 未结 18 2321
逝去的感伤
逝去的感伤 2020-11-27 11:46

I am looking at the chrisbanes/cheesesquare and I am trying to put TabLayout with a Toolbar inside a CollapsingToolbarLayout, and here is my code



        
18条回答
  •  星月不相逢
    2020-11-27 12:07

    Here is my idea of doing this.

    I place tab layout outside the AppBar and wrap it with vertical Linear Layout and set the position like this

    
    
    
    
    

    If you don't wrap TabLayout with another twice height Layout. When you set layout_anchor to AppBar, only half of TabLayout will be in AppBar.

    Here is my whole XML file.

    
    
    
    
    
    
        
    
            
    
            
    
        
    
    
    
    
    
    
    
    

    I'm not sure if these set of dp value will fit your screen size but it do with mine. If anyone has better answer please share.

    Sorry if i make a mistake on my code or my english.Thank you!!

提交回复
热议问题