RecyclerView внутри NestedScrollView не работает - PullRequest
0 голосов
/ 27 июня 2019

У меня есть Layout, содержащий ImageSliderView и RecyclerView, я хочу сделать прокрутку ImageSliderView с помощью RecyclerView, для этого я отключил прокрутку RecyclerView, добавив этот код:

recyclerView = v.findViewById(R.id.rc);
recyclerView.setNestedScrollingEnabled(false);

И я добавил androidx.core.widget.NestedScrollView в качестве родителя, как показано ниже:

<androidx.core.widget.NestedScrollView 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="match_parent"
    android:background="#008080"
    android:fillViewport="false">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#008080"
        android:orientation="vertical"
        app:layout_behavior="@string/bottom_sheet_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:context=".Fragments.Recent">


        <RelativeLayout
            android:id="@+id/relative_page"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:background="@drawable/imageborder"
            android:visibility="visible">

            <com.glide.slider.library.SliderLayout
                android:id="@+id/imgtoday"
                android:layout_width="match_parent"
                android:layout_height="180dp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/relative_page">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rc"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="4dp"
                android:numColumns="2"
                android:scrollbars="vertical" />
        </RelativeLayout>
    </RelativeLayout>
</androidx.core.widget.NestedScrollView>

Приложение зависает во время выполнения, может кто-нибудь помочь мне решить мою проблему

1 Ответ

0 голосов
/ 27 июня 2019

Я столкнулся с той же проблемой, и я закончил тем, что добавил app:layout_behavior="@string/appbar_scrolling_view_behavior" внутри NestedScrollView

<androidx.core.widget.NestedScrollView 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="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="#008080"
    android:fillViewport="false">

Есть люди, которые вместо добавления его к NestedScrollView добавляют внутри RecyclerView иэто тоже работает.

Это помогло мне, и вы можете изменить height на wrap_content

...