【发布时间】:2021-10-20 05:43:48
【问题描述】:
我有一个fragment_layout.xml,带有两个按钮(filter_1_btn、filter_2_btn),它们对RecyclerView 的项目执行过滤。问题是当我滚动一点(因为按钮上方的TextView 包含多行文本)然后应用过滤时,NestedScrollView 在屏幕顶部滚动。有没有办法在过滤后保持相同的滚动高度?
片段布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nested_scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<TextView
android:id="@+id/description_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:text="Very long random text..." />
<Button
android:id="@+id/filter_1_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter 1"/>
<Button
android:id="@+id/filter_2_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter 2"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="24dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
【问题讨论】:
-
能贴一下过滤的代码吗,过滤后的数据怎么设置?
标签: android android-layout android-recyclerview android-nestedscrollview