简体   繁体   中英

TabLayout Indicator slides really slow on Tab selection

I'm using TabLayout with two nested Fragments and I have noticed that when user clicks the other Tab, while the content changes immediately, the indicator move from the first Tab to the second takes literally 3-4 seconds.

I have the same behavior in any device I have so far tried the app (not only genymotion). Nexus 4 and Nexus 5X are some of the testing devices.

The layout is :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:EMVideoView="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:clickable="true"
android:layout_width="match_parent" android:layout_height="match_parent">

<com.devbrackets.android.exomedia.EMVideoView
    android:id="@+id/video_play_activity_video_view"
    android:layout_width="match_parent" android:layout_height="360dp"
    EMVideoView:defaultControlsEnabled="true"/>

<android.support.design.widget.TabLayout
    android:id="@+id/nested_tabs" android:layout_below="@+id/video_play_activity_video_view"
    android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
    app:tabMode="fixed" app:tabGravity="fill"/>

<FrameLayout android:id="@+id/fl_nested_tabs_container" android:layout_below="@+id/nested_tabs"
    android:layout_width="match_parent" android:layout_height="wrap_content"/>

and the code where I change tabs :

@Override
public void onTabSelected(TabLayout.Tab tab) {
    if (isCommentsFragmentSelected) {
        isCommentsFragmentSelected = false;
        getChildFragmentManager()
                .beginTransaction()
                .replace(R.id.fl_nested_tabs_container, PollsFragment.newInstance())
                .commit();
    } else {
        isCommentsFragmentSelected = true;
        getChildFragmentManager()
                .beginTransaction()
                .replace(R.id.fl_nested_tabs_container, CommentsFragment.newInstance())
                .commit();
    }

}

在清单文件中的应用程序标签下使用此属性。

 android:hardwareAccelerated="true"

I was also using nested fragments in a three tab layout with a ViewPager. Setting the offscreen page limit solved the slow loading problem for me.

viewPager.setOffscreenPageLimit(2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM