【问题标题】:RecyclerView SwipeRefreshLayout scrolling does not workRecyclerView SwipeRefreshLayout 滚动不起作用
【发布时间】:2018-09-30 18:31:59
【问题描述】:

我正在尝试使用 SwipeRefresh 和 RecyclerView 实现一个列表,但是,使用 SwipeRefreshLayout 阻止滚动列表。我的布局 xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_contracts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!--<android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">-->

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/list_contracts"/>

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/btn_show_filters"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_filter_list_black_24dp"
        android:tint="@android:color/white"/>

</android.support.design.widget.CoordinatorLayout>

从注释掉的部分可以看出,我也尝试过使用 NestedScrollView,但这也不起作用。

在随附的 java 源文件中,我只为 recyclerview 设置了一个布局管理器和适配器,以及一个用于滑动刷新操作的事件监听器。

提前谢谢你。

【问题讨论】:

  • 尝试使 recyclerView 和 swipeToRefresh 布局高度匹配_parent @maarten
  • @RamzyHassan 遗憾的是没有改变任何东西,scolling 仍然不起作用
  • 刷卡刷新不应影响滚动行为尝试将刷卡布局和回收器放在父相对布局中。看看会发生什么@Maarten

标签: android android-recyclerview swiperefreshlayout


【解决方案1】:

试试这个:

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_contracts"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/list_contracts"/>

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

改变高度和宽度:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 2018-07-20
    • 2019-10-06
    • 1970-01-01
    • 2016-10-24
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多