RecyclerView滞后于NestedScrollView

时间:2018-12-06 12:06:28

标签: android android-studio android-layout android-fragments android-recyclerview

Am在主要活动中具有一个底部的应用栏,仅在使用nestedScrollView时隐藏,但是当将带有recyler视图的片段调用到nestedScrollView中时,它会滞后。

 android:nestedScrollingEnabled="false"

activity_main.xml

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/backgroundcolor"
android:id="@+id/main_page"
android:layout_width="match_parent"

android:layout_height="match_parent">

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frag_replace"/>
<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar

        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:paddingTop="3dp"
        android:paddingBottom="3dp"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:tabMode="scrollable">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:elegantTextHeight="true"
            android:fontFamily="@font/pacifico_regular"
            android:text="@string/app_name"
            android:textColor="@color/colorDrawerBackground"
            android:textSize="25sp" />
    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottom_app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:backgroundTint="?attr/colorPrimary"
    app:fabAlignmentMode="center"
    app:hideOnScroll="true"
    app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
    app:navigationIcon="@drawable/ic_menu_black_24dp"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    style="@style/Widget.MaterialComponents.FloatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add_black_24dp"
    app:layout_anchor="@id/bottom_app_bar" />

片段布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.DailyList">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:nestedScrollingEnabled="false" />

</FrameLayout>

这称为fragment

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.frag_replace, dailyList).commit();

还尝试在Java中设置recyclerview的嵌套滚动视图,但仍然滞后

1 个答案:

答案 0 :(得分:0)

这应该有所帮助:ViewCompat.setNestedScrollingEnabled(recyclerView, false);

有关更多信息,请参阅本文: https://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542