Vanhaeren Thomas
Vanhaeren Thomas

Reputation: 387

SwipeRefreshLayout with NestedScrollView not scrolling

I would like to show a ListView inside a scrollview. This seems to work before adding the SwipeRefresh layout. After adding it, the refresh works but I can no longer scroll.

I believe the problem comes from the XML code. Note that if I use a normal ScrollView, I am able to do both, but I can't scroll back up, because the SwipeRefresh activates.

Here is my XML code:

<RelativeLayout 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:orientation="vertical"
android:fitsSystemWindows="true"
>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_favorites"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_marginBottom="60dp"
            android:id="@+id/friends_scrollLayout"
            android:layout_below="@id/friends_search">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/favorite_horeca_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:fillViewport="true"
            android:scrollbars="none"
            android:scrollingCache="true">

            <LinearLayout
                android:id="@+id/favorite_horeca_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/favorite_horeca_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:dividerHeight="-1dp" />

            </LinearLayout>

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

        </LinearLayout>

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F5F7F8"
    android:visibility="gone"
    >

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:layout_above="@id/empty_text"
        android:layout_marginBottom="20dp"
        android:gravity="center_vertical|center_horizontal"
        android:src="@drawable/ic_logo_vert_rond"
        />

    <TextView
        android:id="@+id/empty_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="No Horecas added to your favorites."
        android:gravity="center_horizontal|center_vertical"/>

</RelativeLayout>

Upvotes: 0

Views: 3988

Answers (3)

Md. Shofiulla
Md. Shofiulla

Reputation: 2315

Use SwipeRefreshLayout as parent layout then use NestedScrollView as child layout

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </androidx.recyclerview.widget.RecyclerView>
    </androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

Upvotes: 3

Vanhaeren Thomas
Vanhaeren Thomas

Reputation: 387

The solution was to just completely remove the Scrollview, no need to add it, SwipeRefreshLayout already has a built-in Scroll.

<RelativeLayout 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:orientation="vertical"
android:fitsSystemWindows="true"
>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_favorites"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="?attr/actionBarSize"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <ListView
                android:id="@+id/favorite_horeca_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:dividerHeight="-1dp" />

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F5F7F8"
    android:visibility="gone"
    >

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:layout_above="@id/empty_text"
        android:layout_marginBottom="20dp"
        android:gravity="center_vertical|center_horizontal"
        android:src="@drawable/ic_logo_vert_rond"
        />

    <TextView
        android:id="@+id/empty_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="No Horecas added to your favorites."
        android:gravity="center_horizontal|center_vertical"/>

</RelativeLayout>

Upvotes: 0

melianor
melianor

Reputation: 170

<CoordinatorLayout 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:orientation="vertical"
android:fitsSystemWindows="true"
>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_favorites"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="?attr/actionBarSize"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/favorite_horeca_scrollview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:fillViewport="true"
            android:scrollbars="none"
            android:scrollingCache="true">

            <LinearLayout
                android:id="@+id/favorite_horeca_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/favorite_horeca_list"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:dividerHeight="-1dp" />

            </LinearLayout>

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

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


<RelativeLayout
    android:id="@+id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F5F7F8"
    android:visibility="gone"
    >

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:layout_above="@id/empty_text"
        android:layout_marginBottom="20dp"
        android:gravity="center_vertical|center_horizontal"
        android:src="@drawable/ic_logo_vert_rond"
        />

    <TextView
        android:id="@+id/empty_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="No Horecas added to your favorites."
        android:gravity="center_horizontal|center_vertical"/>

 </RelativeLayout>

</CoordinatorLayout >

Try like that

Upvotes: 0

Related Questions