android - TabLayout Indicator 在选择 Tab 时滑动非常慢

标签 android android-tablayout

我将 TabLayout 与两个嵌套 fragment 一起使用,我注意到当用户单击另一个选项卡时,内容会立即发生变化,指示器从第一个选项卡移动到第二个选项卡实际上需要 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();
    }

}

最佳答案

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

 android:hardwareAccelerated="true"

关于android - TabLayout Indicator 在选择 Tab 时滑动非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36667730/

相关文章:

Android - 带有 alignParentBottom = "true"的 View 在 ViewPager 中不可见

android - 使用 getChildFragmentManager().beginTransaction() 时的空对象引用

java - Firestore,交易已经完成

Android ViewPager 在加载第一个 fragment 时显示空屏幕,但在向回滑动其他 fragment 时显示正确的内容

android - 在 Tablayout Android 中隐藏选项卡

android - 在 TabLayout 中禁用标签

java - 即使禁用了滑动,选项卡仍会随着 TabLayout 上的触摸移动而更改

Android XML 命名约定

java - 我应该为我的适配器使用 View Holder 模式吗?

android - 不使用 ViewPager 的 TabLayout