我有一个带有Framelayout的嵌套滚动视图:
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
我要向该容器添加多个片段。片段之一包含大小固定为(200dp * 200dp)的RecyclerView,其中包含20个项目。在最大化RecyclerView之前,它包含3个项目,当我长按它时,我需要使其最大化。为此,我正在更改RecyclerView的高度以匹配父级。 RecyclerView的更改高度工作正常,但是当我通过更改RecyclerView的高度最小化列表时(或者最小化或最大化它时),列表会自动滚动。我想一直呆在那里,即使我确实最大化或最小化了RecyclerView。
如何在最小化或最大化RecyclerView的同时停止滚动。
我尝试将其设置为嵌套滚动视图的子级,如建议here:
android:descendantFocusability="blocksDescendants"
但还是同样的问题。
答案 0 :(得分:1)
在recyclerview下面添加此内容。就我而言,它奏效了...
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
添加NestedScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedscroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
//add your recycler view
</androidx.core.widget.NestedScrollView>