android - viewpager2 中的 recyclerView 将在导航中从下一页返回后自动向上滚动
问题描述
viewpager2 布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/home_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:tabGravity="center"
app:tabIndicatorFullWidth="false" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/home_viewpager2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/home_tab" />
</androidx.constraintlayout.widget.ConstraintLayout>
viewpager2 的适配器创建了两个包含 recyclerView 片段布局的片段:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/sub_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
滚动到recyclerView的底部并单击一项以导航到下一页并单击系统后退按钮,recyclerView将自动滚动仅在recyclerView底部发生的一项
解决方案
推荐阅读
- android - 测试完成 - 真实设备中的 Andriod 自动化 - 名称映射包含重复对象(设备、设备 2、Windows、Windows2)
- c++ - 组合多个 boost property_tree
- python - 在函数上使用数据对象的最佳实践
- vulkan - 让我们直接获取交换链的图像计数
- javascript - 使用for循环制作函数输入console.log?
- python - 将数据从搜索栏发送到 url
- android - Flutter 后台定位访问
- python-3.x - python的websocket在哪里存储它接收到的数据
- arm - 在 STM32 上使用 FreeRTOS 处理多个中断
- php - 如何使嵌入的 pdf 文件在我的网站上全屏显示?