material-components / material-components/material-components-android
[TabLayout] TabLayout Scroll Bug: Left Tab Misalignment After Fast Scroll
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
When performing a fast horizontal scroll that moves the entire TabLayout to the right, we expect the leftmost tab to return to an x = 0 position.
However, it appears that the leftmost tab occasionally snaps back to a negative x-position instead.
When this happens, tapping on any tab has no immediate effect. Instead, multiple taps are required before the leftmost tab returns to a non-negative x-position.
Until it returns to the correct position, all tab taps become unresponsive, except that they seem to gradually nudge the layout back toward alignment.
In the video, you can observe a small gap between the leftmost tab and the screen’s edge immediately after a fast scroll - this gap indicates the misalignment.
https://youtu.be/tl8PDvkRHYo
**Expected behavior:** Left most tab will never reach negative x position
**Source code:**
private void initTabs() {
if (noteFragmentStateAdapter == null) {
noteFragmentStateAdapter = new NoteFragmentStateAdapter(this, tabInfos);
viewPager.setAdapter(noteFragmentStateAdapter);
new TabLayoutMediator(tabLayout, viewPager,
(tab, position) -> tab.setText(noteFragmentStateAdapter.getPageTitle(position))
).attach();
viewPager.unregisterOnPageChangeCallback(onPageChangeListener);
viewPager.registerOnPageChangeCallback(onPageChangeListener);
// http://stackoverflow.com/questions/9857420/viewpager-fragments-getting-destroyed-over-time
viewPager.setOffscreenPageLimit(1);
} else {
noteFragmentStateAdapter.notifyDataSetChanged();
}
int selectedNoteTabIndex = WeNoteOptions.getSelectedNoteTabIndex();
setSelectedNoteTab(selectedNoteTabIndex);
}
**Minimal sample app repro:** (Sorry. I will provide a sample in next few days)
**Android API version:** Android API 35
**Material Library version:** [Material Android Library version you are using here (e.g., 1.1.0-alpha07)](com.google.android.material:material:1.12.0)
**Device:** Emulator Pixel 8 Pro API 35 arm64-v8a
https://github.com/user-attachments/assets/dfc811b2-35a6-4a52-925b-78d1d94390fa
To help us triage faster, please check to make sure you are using the [latest version](https://github.com/material-components/material-components-android/releases) of the library.
We also happily accept [pull requests](https://github.com/material-components/material-components-android/pulls).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the initTabs() entry point shown in the report and reproduce the fast horizontal scroll on the Pixel 8 Pro API 35 emulator with Material 1.12.0. Confirm the leftmost tab does not reach a negative x-position and that tab taps respond immediately after the scroll.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100