【问题标题】:TabLayout Indicator slides really slow on Tab selectionTabLayout Indicator 在选项卡选择上滑动真的很慢
【发布时间】:2016-08-08 15:23:51
【问题描述】:

我将TabLayout 与两个嵌套片段一起使用,我注意到当用户单击另一个选项卡时,虽然内容立即更改,但指示器从第一个选项卡移动到第二个选项卡实际上需要 3-4 秒。

到目前为止,我在尝试过该应用程序的任何设备上都有相同的行为(不仅是 genymotion)。 Nexus 4 和 Nexus 5X 是一些测试设备。

布局是:

<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"/>

以及我更改标签的代码:

@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 android-tablayout


    【解决方案1】:

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

     android:hardwareAccelerated="true"
    

    【讨论】:

      【解决方案2】:

      我还在带有 ViewPager 的三选项卡布局中使用嵌套片段。设置offscreen page limit 为我解决了加载缓慢的问题。

      viewPager.setOffscreenPageLimit(2);
      

      【讨论】:

        猜你喜欢
        • 2015-08-28
        • 1970-01-01
        • 2018-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多