【发布时间】:2017-05-25 09:13:28
【问题描述】:
我发现 RecyclerView 在 Nexus 6P API 25 7.1.1 模拟器上不一致地激活 SwipeRefreshLayout 存在问题。 我们使用的是最新版本的支持库:
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
我有一个带有数据集的 RecyclerView,该数据集在发生拉动刷新(将项目添加到顶部)时预先添加,它在我的布局中声明如下:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</android.support.v4.widget.SwipeRefreshLayout>
我能够触发手势大约 2-3 次,将项目添加到 RecyclerView 但它不再允许我触发拉动刷新。我们从不调用 SwipeRefreshLayout.setEnabled(false)。即使我们位于项目列表的顶部,RecyclerView 似乎也在内部对 canScrollVertically(-1) 做出响应。
我们处理的唯一有趣的事情是我们覆盖了 RecyclerView 的布局管理器,让我们滚动到底部:
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setStackFromEnd(true); // Start with most recent messages (enables scroll-to-bottom)
recyclerView.setLayoutManager(llm);
【问题讨论】:
标签: android android-recyclerview android-support-library swiperefreshlayout