问题:当这两个一起使用时出现了一个滑动冲突的问题,当滑动到下面的时候,快速下拉出现刷新,应该是展示上面的条目数据。
1. 使用布局格式
这两个结合使用时必须按照如下格式使用,否则容易出现滑动或者其他问题。
<com.baoyz.widget.PullRefreshLayout
android:id="@+id/prl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.jdsjlzx.recyclerview.LRecyclerView
android:id="@+id/lrv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</com.github.jdsjlzx.recyclerview.LRecyclerView>
</LinearLayout>
</ScrollView>
</com.baoyz.widget.PullRefreshLayout>
2. 解决滑动冲突的代码
//解决LRecycleview和PullRefreshLayout下拉冲突
mLrv.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
int topRowVerticalPosition =
(recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
mPrl.setEnabled(topRowVerticalPosition >= 0);
}
});
我的已解决,希望能帮到你!!!