8

我在滚动视图中使用 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

4

2 回答 2

11

尝试这个,

<?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>
于 2016-10-20T08:55:54.470 回答
0

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>
于 2019-09-17T06:16:01.860 回答