【发布时间】:2016-01-11 05:58:11
【问题描述】:
我的 android 项目包括一个包含 cardView 列表的 recyclerView,并且在这个 recyclerView 的顶部还有一个 swipeRefreshLayout。当我向下滚动列表并拉出那些cardViews 时,我只想禁用swipeRefreshLayout。也就是说,当 RecyclerView 不在第一个 item 上时,如果用户想要回滚到第一个 item,它一定不能显示 swipeRefreshLayout。
我在 Google 上搜索了很多关于这个问题的信息,有一些解决方案可以覆盖 onScrollStateChanged 方法,但它们的行为不是很流畅,并且在某些情况下仍然启用 swipeRefreshLayout。
编辑 1: 以下链接包括我上面提到的一些解决方案:
https://stackoverflow.com/a/27042911/4257703
https://gist.github.com/NikolaDespotoski/1a6bb83dbae133f67812
这是我的 xml 布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:choiceMode="none"
android:focusable="false"
android:listSelector="@android:color/darker_gray" />
<ImageView
android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" />
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
编辑 2: 今天我意识到我的问题是由于同时实现 Tabs 和 swipeRefreshLayout 而发生的。要刷新包含 RecyclerView 的 Fragment 的数据,用户必须将页面拖到底部,另一方面,要在选项卡之间切换,用户必须将屏幕向右或向左拖动。由于这种触摸手势,滚动我的列表时会出现一些错误和滞后。请帮我解决这个问题。非常感谢。
【问题讨论】:
-
有人可能已经有了现成的答案,否则总结或提供您尝试过的解决方案的链接可能会有所帮助,并说明它们在哪些方面不符合您的需求。
-
你能发布你的 layout.xml 吗?
标签: android material-design android-recyclerview swiperefreshlayout