Android中PullRefreshLayout和LRecyclerView結合使用遇到的問題

問題:當這兩個一起使用時出現了一個滑動衝突的問題,當滑動到下面的時候,快速下拉出現刷新,應該是展示上面的條目數據。

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);
            }
        });

我的已解決,希望能幫到你!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章