0

Имеется такая ситуация: ScrollView -> ViewPager -> RecyclerView.

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"
    android:scrollbars="none"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/viewPagerTasksGoalsMenu"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="8dp" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Дальше я в коде помещаю во ViewPager фрагмент:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textMenuTasksInfo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list_tasks_launcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:orientation="vertical"
        android:overScrollMode="never"
        android:paddingBottom="12dp"
        android:scrollbars="none"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textMenuTasksInfo" />

</androidx.constraintlayout.widget.ConstraintLayout>

В итоге у меня листается RecyclerView. Но мне нужно, чтобы прокручивалась страница с этим RecyclerView. Грубо говоря, чтобы RecyclerView был статичен. Как это можно сделать?

2 ответа 2

0

Для того, чтобы он был статичен используется не ScrollView , а NestedScrollView(параметр fillviewport включен по умолчанию в Nested'е)

4
  • не знаю, как отреагирует ViewPager. если не получится, то оберните именно сам RecyclerView в NestedScrollView. должно работать 100%, сам недавно с этим мучался
    – Wlad
    31 июл 2021 в 10:22
  • 1
    Почему вы пишете комментарий, а не редактируете ответ?
    – 0xdb
    31 июл 2021 в 10:39
  • Попробовал Nested и с указанным fillviewport и не указанным. Попробовал обернуть и recyclerview и viewpager, и вместе, и по одиночке в nested. Всё равно, никак не хочет :( 31 июл 2021 в 10:44
  • @ВикторШамрук попробуйте сделать без ViewPager
    – Wlad
    31 июл 2021 в 12:00
0

Решил проблему следующим образом:

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:overScrollMode="never"
            android:scrollbars="none"
            app:layout_constraintTop_toBottomOf="@id/scrollTasksGoalsTabs"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/viewPagerTasksGoalsMenu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </androidx.core.widget.NestedScrollView>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.