SwipeRefreshLayout中的RecyclerView不显示

时间:2016-10-20 08:39:16

标签: android android-layout android-recyclerview swiperefreshlayout recyclerview-layout

我在scrollview中使用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的设备和预览中)

你能弄清楚如何解决这个问题。在此先感谢!!

修改的 这是我想要做的 Scroll itself
Refresy RecyclerView

2 个答案:

答案 0 :(得分:5)

试试这个,

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

答案 1 :(得分:0)

  

在ScroolView中使用SwipeRefreshLayout创建问题

使用这个为我工作。

<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"
        tools:context=".Fragments.AccountsFragment">

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