Solve the problem that Android TabLayout can not be evenly distributed on wide screen tab

  • 2021-12-05 07:20:55
  • OfStack

When TabLayout is on a wide screen device, such as a flat horizontal screen, when the width of tab exceeds a fixed value of 1, it is not in the average distribution width, but is displayed in the center.

Set at this time

app:tabMode="fixed"

Or

top_table.setTabMode(TabLayout.MODE_FIXED);

It's not working.

app:tabMaxWidth="0dp"

This value can be solved!


<android.support.design.widget.TabLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:tabMaxWidth="0dp"
   app:tabGravity="fill"
   app:tabMode="fixed" />

Additional knowledge: When there are too many TabLayout tags, the Tab display is crowded, resulting in incomplete ellipsis display

Change the control to add this property in the layout file

app:tabMode="scrollable"


Related articles: