0

We are using ViewPager2 and TabLayout.

We tried to disable animation by following https://stackoverflow.com/a/62579862/72437

Our code looks like

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:parentTag="android.widget.LinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.tabs.TabLayout
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabIndicatorColor="#ff0000"
        app:tabIndicatorHeight="2dp"
        app:tabIconTint="@color/tab_icon_selector"
        app:tabIndicatorAnimationMode="fade"
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</merge>

// autoRefresh = true
// smoothScroll = false
new TabLayoutMediator(tabLayout, viewPager, true, false,
        (tab, position) -> {
            tab.setCustomView(R.layout.emoji_category_tab);

            tab.setIcon(EmojiCategory.values()[position].resourceId);
        }

).attach();

It works pretty good, when we tap on the TabLayout's tab explicitly. There is no animation.

Tap on TabLayout's tab

enter image description here

However, when we left-right swipe on ViewPager2, the tab indicator is having bad fade coloring.

Left-right swipe on ViewPager2 (Bad indicator fade coloring)

enter image description here

The gif file might not show such bad coloring clearly. You can view the bad fade coloring in this video - https://stackoverflow.com/a/61304247/72437

I am expecting the indicator color to be non-transparent. But it isn't.

May I know, what we are not doing correctly? Thanks.


To make the problem more obvious, I change from fade to app:tabIndicatorAnimationMode="linear".

Here's the outcome

enter image description here

It seems that if I left-right swipe on ViewPager2, incomplete animation is performed on the TabLayout's indicator. But why?

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

0 Answers0