Android Support Design TabLayout: Gravity Center and Mode Scrollable

前端 未结 13 2028

I am trying to use the new Design TabLayout in my project. I want the layout to adapt to every screen size and orientation, but it can be seen correctly in one orientation.<

13条回答
  •  盖世英雄少女心
    2020-12-02 07:23

    Tab gravity only effects MODE_FIXED.

    One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal:

    
    

    If the tabs are smaller than the screen width, the TabLayout itself will also be smaller and it will be centered because of the gravity. If the tabs are bigger than the screen width, the TabLayout will match the screen width and scrolling will activate.

提交回复
热议问题