【问题标题】:NestedScrollView inside a ReyciclerView not scrollingReyciclerView 内的 NestedScrollView 不滚动
【发布时间】:2020-08-29 22:01:42
【问题描述】:

我有一个ViewPager,其中包含一个RecyclerView,它可以垂直滚动并使用适配器显示项目。每个项目都有一个NestedScrollView,它也应该垂直滚动。问题是当我尝试滚动 NestedScrollView 时,它会滚动父 ViewPager

我该如何解决这个问题?

这是 RecyclerView:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/offersRecyclerView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="@drawable/table_cell_background"
    android:fadeScrollbars="false"
    android:scrollbars="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

这是项目的布局,其中包含 NestedScrollView:

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/statusConstraintLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@drawable/table_background"
        android:padding="@dimen/spacing_small"
        app:layout_constraintStart_toEndOf="@+id/salaryConstraintLayout"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.55">

        <androidx.core.widget.NestedScrollView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/statusValue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/offer_sent_with_three_dots"
                    android:textSize="@dimen/mini_text"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    </androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • ViewPager 是垂直的还是水平的?
  • 另外,我还没有对此进行测试,所以它可能会或可能不会起作用,但请尝试一下 ViewPager2:它基于 RecyclerView,因此应该更好地处理嵌套滚动。

标签: android android-recyclerview android-scrollview android-nestedscrollview


【解决方案1】:

你也可以在 RecyclerView 中试试这个

android:nestedScrollingEnabled="true"

【讨论】:

  • ConstraintLayout 的item 布局能否限制在layout_height 上。这里使用匹配父级。您可以改为 wrap_content 并检查吗?
【解决方案2】:

尝试将此属性app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到nestedScrollView

【讨论】:

    猜你喜欢
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2019-10-17
    相关资源
    最近更新 更多