android - RecyclerView 滞后于 NestedScrollView
问题描述
我在主要活动中有一个底部应用程序栏,它只在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();
还尝试recyclerview
在java中设置嵌套滚动视图但仍然滞后
解决方案
这应该有助于:ViewCompat.setNestedScrollingEnabled(recyclerView, false);
有关更多信息,请参阅本文: https ://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542
推荐阅读
- c# - C# DTLS 实现(服务器/客户端)
- ios - ios - 如何使用 Swift 4 延长位置跟踪时间
- c# - System.EntryPointNotFoundException + 无法安装包“SQLite.Interop.dll 1.0.103”。我的项目目标是'.NETFramework,Version=v4.6.1'
- cucumber - cucumber.runtime.CucumberException:无法实例化 stepDefinitions 类
- node.js - 将数据从节点 js 服务器发送到 React js 组件
- javascript - 如何在处理时在Javascript中为类数组赋值
- python - 通过按下 tkinter 按钮启动子进程
- java - 尝试创建 JUnit 构建配置会导致错误“在模块中找不到 JUnit”(IntelliJ)
- android - 无法将“android.app.activty”转换为“com.HomeFragment”
- firebase - 如何使用 Firebase Cloud Firestore 对方法进行单元测试?