question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TabLayout] Indicator with tabIndicatorFullWidth=false does not match label if label is not centered

See original GitHub issue

Description:

I have this style

<style name="TabLayoutStyle" parent="Widget.MaterialComponents.TabLayout">
		<item name="tabIndicatorFullWidth">false</item>
		<item name="tabMode">scrollable</item>
		<item name="tabPaddingStart">0dp</item>
		<item name="tabPaddingEnd">16dp</item>
		<item name="tabGravity">start</item>
		<item name="tabContentStart">0dp</item>
		<item name="tabMinWidth">0dp</item>

	</style>

and it renders as this Screenshot_20200617-110524

Expected behavior:

Indicator should match label width

Android API version: 29

Material Library version: 1,3.0-alpha01

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
denis-bezrukovcommented, Oct 27, 2020

Is there a workaround for this? Or will you accept a PR with a fix?

after a quick look, it seems that tabViewCenterX should take paddings into account

tabViewCenterX = (tabView.getLeft() + tabPaddingStart + tabView.getRight() - tabPaddingEnd) / 2;

// instead of 

tabViewCenterX = (tabView.getLeft() + tabView.getRight()) / 2;

in https://github.com/material-components/material-components-android/blob/0afcb48f14a7af3db3712be44d7984c8d89e25fb/lib/java/com/google/android/material/tabs/TabIndicatorInterpolator.java#L80

UPD as a workaround you can use equal start/end paddings and just translate the whole TabLayout by difference between original padding and new one. e.g.

<item name="tabPaddingStart">0dp</item>
<item name="tabPaddingEnd">16dp</item>

can be achieved as

<item name="tabPaddingStart">8dp</item>
<item name="tabPaddingEnd">8dp</item>
<item name="translationX">-8dp</item> // it's old tabPaddingStart - new tabPaddingStart (0dp - 8dp)
0reactions
AramKocharyancommented, Nov 8, 2022

Is this fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Tab layout: Wrap tab indicator width with respect to ...
Yes, it's possible to wrap tab indicator as title setting padding to 0 ... If you don't need the strip to be smaller...
Read more >
TabLayout | Android Developers
Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons. boolean ...
Read more >
Custom TabLayout Indicator in — Android. | by Danish Amjad
Custom TabLayout Indicator on Android 9.0. The issue was it's not picked up the color which I defined in my drawable, now let's...
Read more >
All-in-One — Android TabLayout and TabItem | by Myrick Chow
Do not use app:tabIndicatorHeight to change the height of indicator since it ... time and each tab has equal width which is based...
Read more >
Tabs - Material Design
TabItem s can then be added as children of the TabLayout and adjusted as needed: ... Active tab indicator; Inactive icon (optional if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found