【发布时间】:2015-12-02 08:30:52
【问题描述】:
我目前正在我的项目中实现 swiperefreshlayout,当时我遇到了一个问题,即 swiperefresh 图标停止并且没有动画也根本不刷新。它只是呆在那里,什么也没有发生。我想这是布局的问题,所以这是我当前的布局 XML:
主要活动:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<com.myapp.customviews.CustomViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/colors"
android:layout_below="@+id/tabs"
tools:context=".MainActivity"
android:layout_gravity="right|top" />
<include android:id="@+id/toolbar" layout="@layout/toolbar" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/blue"
android:layout_marginTop="?attr/actionBarSize"
android:layout_gravity="right|top" />
</FrameLayout>
所以我的主要活动包括一个框架布局和一个自定义视图寻呼机,它可以切换分页启用和禁用。一个工具栏和一个标签条。工具栏将隐藏在使用此布局的回收器视图的滚动上:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:id="@+id/swipe_home">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"
android:clipToPadding="false"/>
</android.support.v4.widget.SwipeRefreshLayout>
现在这个布局被用在一个片段中,该片段被添加到主要活动的视图寻呼机中。我只是为我的 recyclerview 设置了一个填充,以确保项目内容正确显示,但是当我拉动刷新它时,圆形刷新图标 swiperefreshlayout 就停止了,问题就出现了。我以前研究过 swiperefresh 布局,但这是我第一次遇到这个问题。希望有人能指出问题出在哪里。
更新:
我尝试将滑动刷新的内容从 RecyclerView 更改为 ScrollView,并且下拉刷新工作正常!但是滚动视图不是我需要的,所以我需要推动仍然无法工作并冻结的 RecyclerView。我认为 RecyclerView 和 SwipeRefreshLayout 的实现有问题。
【问题讨论】:
-
你能展示你的 SwipeRefreshLayout 的 java 代码吗?
-
我目前还没有在 SwipeRefreshLayout 上实现代码,因为对于 recyclerview 我只是使用测试数据来添加列表项,没有别的。它适用于其他可滚动视图,但不适用于 recyclerview。奇怪的是,我之前尝试过这个并且效果很好,但现在我只是冻结了。我今天会检查我的库,可能有一些冲突
-
查看 link 以获取 swiperefresh 布局示例。
-
我使用的布局已经很好了。问题出在支持库上,所以我刚刚更新了它,现在它可以工作了。
标签: android android-layout swiperefreshlayout