SlidingTabLayout to fit the screen

前端 未结 9 1537
南笙
南笙 2020-12-07 18:45

I am using Google\'s SlidingTabLayout. As i only have 3 tabs to be displayed, I am seeing empty space after last tab. Please screenshot below.

相关标签:
9条回答
  • 2020-12-07 19:23

    try this android:layout_weight="1" in your xml layout for each textview.

    0 讨论(0)
  • 2020-12-07 19:28

    SubliemeSiem's answer is on the right track. A more flexible, and shorter, answer is to add a weight of 1 to each TextView that makes up a tab.

    In SlidingTabLayout.java, find

    protected TextView createDefaultTabView(Context context)
    

    It was line 171 at the time of writing. Add this line to the function.

    textView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
    

    TableLayout.LayoutParams takes three arguments, the final of which is weight. As all views in the horizontal layout will have equal weight they will be equally sized. The wrap content should allow for graceful behaviour as the number of tabs increases and the size overflows the width of the screen, but I haven't tested that..

    0 讨论(0)
  • 2020-12-07 19:32

    Google have released Design Support Library. You can now use TabLayout. To make tabs fits the screen you can call setTabMode(TabLayout.MODE_FIXED);

    0 讨论(0)
提交回复
热议问题