简体   繁体   English

带有SwipeRefreshLayout的RecyclerView无法正常工作

[英]RecyclerView with SwipeRefreshLayout is not working consistently

I know similar question is asked many times but it couldn't solve my issue. 我知道类似的问题曾被问过很多次,但无法解决我的问题。 So I am asking here. 所以我在这里问。 I have a recyclerView with swiperefresh layout. 我有一个带有swiperefresh布局的recyclerView。 I have used this code 我已经使用了这段代码

recyclerView1.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                //super.onScrollStateChanged(recyclerView, newState);
                try {
                    int firstPos = mLinearLayoutManager.findFirstCompletelyVisibleItemPosition();
                    if (refreshLayout != null) {
                        if (firstPos > 0) {
                            refreshLayout.setEnabled(false);
                        } else {
                            activity.refreshLayout.setEnabled(true);
                            if (recyclerView1.getScrollState() == 1)
                                if (activity.refreshLayout.isRefreshing())
                                    recyclerView1.stopScroll();
                        }
                    }

                } catch (Exception e) {

                }
            }
        });

to differentiate the scroll of recyclerView and swipe refresh layout. 区分recyclerView的滚动和滑动刷新布局。 But I have added a header to this recyclerView using this [ Is there an addHeaderView equivalent for RecyclerView? 但是我使用这个[ 在RecyclerView上有一个addHeaderView等效项吗? . Now the header height in the recyclerview is too big so in small devices 现在,recyclerview中的标题高度太大,因此在小型设备中

int firstPos = mLinearLayoutManager.findFirstCompletelyVisibleItemPosition();

is returning 0 when only half of the header is visible. 当只有标题的一半可见时,返回0。 And it is enabling swiperefreshlayout. 它启用了swiperefreshlayout。 So I can't see the whole header in recyclerView. 所以我在recyclerView中看不到整个标题。 Can anybody help me to solve this. 谁能帮我解决这个问题。

Thanks 谢谢

LinearLayoutManager llm = new LinearLayoutManager(getActivity());
refreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshLayout.setRefreshing(true);
            // start refresh
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                        refreshLayout.setRefreshing(false);
                         }
            }, 5000);
        }
    });


    recList.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);

        }
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                refreshLayout.setEnabled(llm.findFirstCompletelyVisibleItemPosition() == 0);
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 RecyclerView 的 SwipeRefreshLayout 在 Fragment 中不起作用 - SwipeRefreshLayout with RecyclerView not working in Fragment SwipeRefreshLayout停止工作/ RecyclerView不一致地触发SwipeRefreshLayout - SwipeRefreshLayout stops working / RecyclerView inconsistently triggers SwipeRefreshLayout 带有 Recyclerview 和 SwipeRefreshLayout 的折叠工具栏无法正常工作 - Collapsingtoolbar With Recyclerview and SwipeRefreshLayout Not working Properly RecyclerView滚动不适用于Fragment中的SwipeRefreshLayout - RecyclerView scrolling not working with SwipeRefreshLayout in Fragment 拉SwipeRefreshLayout刷新Android中的片段中的RecyclerView,但不起作用 - Pull SwipeRefreshLayout to refresh RecyclerView In Fragment in android but Not Working RecyclerView 和 SwipeRefreshLayout - RecyclerView and SwipeRefreshLayout 使用Kotlin,RecyclerView.addOnScrolledToEnd和SwipeRefreshLayout.setOnRefreshListener无法正常工作 - RecyclerView.addOnScrolledToEnd and SwipeRefreshLayout.setOnRefreshListener is not working correct with Kotlin SwipeRefreshLayout-未将RecyclerView下拉 - SwipeRefreshLayout - the RecyclerView is not pulled down SwipeRefreshLayout隐藏在空的RecyclerView上 - SwipeRefreshLayout is hidden on empty RecyclerView Android SwipeRefreshLayout与RecyclerView - Android SwipeRefreshLayout with RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM