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.
try this android:layout_weight="1"
in your xml layout for each textview.
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..
Google have released Design Support Library. You can now use TabLayout
. To make tabs fits the screen you can call setTabMode(TabLayout.MODE_FIXED);