Android TabLayout: distribute evenly
Asked Answered
D

1

9

I'm looking at the Google class that was used in the Google IO called SlidingTabLayout. Inside that class, there is a method called setDistributeEvenly which allows all those tabs to have an even distribution on the screen - every tab has the same size: Align-Center SlidingTabLayout

I'm trying to do the same with the official tabLayout class: https://developer.android.com/reference/android/support/design/widget/TabLayout.html

But there doesn't seem to be a method available to make all the tabs evenly distributed.

Am I missing something and is there a method within the class which will let me do this?

Double answered 22/9, 2015 at 9:59 Comment(0)
D
27

I read this tutorial to get my answer: https://web.archive.org/web/20160314043730/http://panavtec.me/playing-with-the-new-support-tablayout/

You are suppose to set the tabLayout gravity:

tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

And do not set your tabLayout to scrollable (app:tabMode="scrollable") otherwise the gravity fill will not work.

Double answered 7/10, 2015 at 12:1 Comment(1)
I needed to prevent line breaks with app:tabMode="scrollable" and evenly distribute the tabs with app:tabGravity="fill"? Any workaround to ensure the two work nicely together.Amplitude

© 2022 - 2024 — McMap. All rights reserved.