8

I implemented one horizontal-scroll item listview using RecyclerView inside scrollview. I want to update the item when user swipe to the end of the listview (item is added after refreshing). The following code is the layout implementation.

<?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>

Before I add SwipeRefreshLayout, everything works fine (items in RecyclerView shown normally), but after I add SwipeRefreshLayout, RecyclerView is gone (both in the device and preview in Android Studio)

Could you figure out how to fix this problem. Thanks in advance!!

EDIT Here are what I want to do Scroll itself
Refresy RecyclerView

Pandarian Ld
  • 727
  • 3
  • 13
  • 25

2 Answers2

12

Try this,

<?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>
devgun
  • 1,003
  • 13
  • 33
  • A main layout should be scrollable. Actually there are many items inside ScrollView. – Pandarian Ld Oct 20 '16 at 09:04
  • let swiperefresh layout be parent and add a nested scrollview inside that linearlayout and place your items there. – devgun Oct 20 '16 at 09:06
  • What about there are more than one RecyclerView with SwipeRefresh in the same page? Maybe I need to add some screenshot to make the problem clearer. – Pandarian Ld Oct 20 '16 at 09:37
  • check the edited answer. You can add number of recyclerview like this. But if you want to refresh each recyclerview separately i suggest you to have buttons in the gray portion of your screen shots. – devgun Oct 20 '16 at 10:32
  • This is what I was looking for. Thank you. – viper Feb 26 '19 at 08:54
0

Using SwipeRefreshLayout inside ScrollView is creating Problem

Use this one working for me.

<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>
Akshay
  • 2,506
  • 4
  • 34
  • 55
Sujeet Kumar
  • 1,822
  • 22
  • 25