【问题标题】:RecyclerView lags inside NestedScrollViewRecyclerView 滞后于 NestedScrollView
【发布时间】:2019-05-08 03:11:19
【问题描述】:

我在主活动中有一个底部应用程序栏,它仅在使用 nestedScrollView 时隐藏,但是当将具有回收器视图的片段调用到 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 的嵌套滚动视图,但仍然滞后

【问题讨论】:

  • 根据您加载的数据的类型和数量,如果是图像,您可能需要检查加载这些图像的方式...
  • 活动布局中的 R.id.frag_replace 在哪里?
  • 是layout_main.xml中嵌套的Scroll视图
  • 您发送的布局是否正确?因为你的nestedScrollView 已经结束并且不包含任何东西!!!

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


【解决方案1】:

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

更多信息请参考这篇文章: https://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542

【讨论】:

  • 不,它仍然滞后
猜你喜欢
  • 2017-07-15
  • 2023-04-06
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多