调整recyclerview大小时滚动问题

问题描述 投票:0回答:1

我有一个带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)的回收者视图,其中包含20个项目。在最大化回收器视图之前,其中有3个项目,当我长按它时,我需要使其最大化。为此,我正在更改回收者视图的高度以匹配父对象。更改回收站视图的高度可以正常工作,但是当我通过更改回收站视图的高度(或同时使其最小化或最大化)最小化列表时,列表会自动滚动。我想一直呆在那里,即使我确实最大化或最小化回收者视图。

如何在最小化或最大化回收者视图的同时停止滚动。

我尝试将其设置为嵌套滚动视图的子级,如建议的here

android:descendantFocusability="blocksDescendants"

但仍然是同一问题。

android android-recyclerview android-nestedscrollview
1个回答
0
投票

在回收站视图下面添加此内容。就我而言,它奏效了...

    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>
© www.soinside.com 2019 - 2024. All rights reserved.