RecyclerView внутри SwipeRefreshLayout не отображается

Я реализовал один список элементов с горизонтальной прокруткой, используя RecyclerView внутри прокрутки. Я хочу обновить элемент, когда пользователь прокручивает список до конца (элемент добавляется после обновления). Следующий код является реализацией макета.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layoutManager="android.support.v7.widget.LinearLayoutManager">

            </android.support.v7.widget.RecyclerView>
        </android.support.v4.widget.SwipeRefreshLayout>

    </LinearLayout>

</ScrollView>

До добавления SwipeRefreshLayout все работает нормально (элементы в RecyclerView отображаются нормально), но после добавления SwipeRefreshLayout RecyclerView исчезает (как на устройстве, так и в предварительном просмотре в Android Studio)

Не могли бы вы выяснить, как решить эту проблему. Заранее спасибо!!

РЕДАКТИРОВАТЬ Вот что я хочу сделать Сама прокрутка
Refresy RecyclerView


person Pandarian Ld    schedule 20.10.2016    source источник
comment
добавить SwipeRefreshLayout в родительский элемент и удалить вид прокрутки   -  person Pavya    schedule 20.10.2016


Ответы (2)


Попробуй это,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layoutManager="android.support.v7.widget.LinearLayoutManager" />

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layoutManager="android.support.v7.widget.LinearLayoutManager" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

</android.support.v4.widget.SwipeRefreshLayout>
person devgun    schedule 20.10.2016
comment
Основной макет должен быть прокручиваемым. На самом деле внутри ScrollView много элементов. - person Pandarian Ld; 20.10.2016
comment
пусть макет swiperefresh будет родительским, добавьте вложенный вид прокрутки внутри этого linearlayout и поместите туда свои элементы. - person devgun; 20.10.2016
comment
Как насчет того, чтобы на одной странице было несколько RecyclerView с SwipeRefresh? Может быть, мне нужно добавить скриншот, чтобы прояснить проблему. - person Pandarian Ld; 20.10.2016
comment
проверьте отредактированный ответ. Вы можете добавить количество recyclerview следующим образом. Но если вы хотите обновить каждый recyclerview отдельно, я предлагаю вам иметь кнопки в серой части ваших снимков экрана. - person devgun; 20.10.2016
comment
Это то, что я искал. Спасибо. - person viper; 26.02.2019

Использование SwipeRefreshLayout внутри ScrollView создает проблему

Используйте этот, работающий на меня.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

            <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layoutAnimation="@anim/layout_animation"
                    android:nestedScrollingEnabled="false">
                </androidx.recyclerview.widget.RecyclerView>

            </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</RelativeLayout>
person Sujeet Kumar    schedule 17.09.2019