带NestedScrollView的SwipeRefreshLayout不滚动

时间:2018-12-12 19:37:52

标签: android xml scrollview swipe swiperefreshlayout

我想在滚动视图中显示一个ListView。在添加SwipeRefresh布局之前,这似乎可行。添加后,刷新工作正常,但我无法再滚动。

我相信问题来自XML代码。请注意,如果我使用普通的ScrollView,则可以同时执行两个操作,但由于SwipeRefresh会激活,因此无法向上滚动。

这是我的XML代码:

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

3 个答案:

答案 0 :(得分:0)

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

那样尝试

答案 1 :(得分:0)

解决方案是完全删除Scrollview,无需添加它,SwipeRefreshLayout已经具有内置的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>

答案 2 :(得分:0)

使用SwipeRefreshLayout作为父布局,然后使用NestedScrollView作为子布局

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