I have added TabLayout
(from support library v22.2.1) to my Fragment as:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MyColorAccentTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
The issue is that when the Fragment's orientation is landscape (before or after the initial creation of the fragment), the TabLayout
doesn't match the width of the Fragment
(yes the parent has its width set to match_parent
as well).
When screen width is small (i.e not all tabs can be shown at same time):
When screen width is big enough to show all tabs (see the blank space at the right):
If I change tabMode
to fixed, width is filled but tabs are too small. Is there any proper solution out there?
Try this one, it's a workaround which sets
tabMaxWidth="0dp"
,tabGravity="fill"
andtabMode="fixed"
.Screenshot on a 10 inch tablet:
Please check this i think it works
public class MainActivity extends AppCompatActivity {
}
please use this it will solve this problem definitely
You should set app:tabMode="fixed" when you want to show tabs 'fill'.
@dtx12 answer doesn't work if any tab title is bigger than (measuredWidth/ tabCount).
There is my
TabLayout
subclass for this situation (in Kotlin). I hope this will help someone.