当前位置:  开发笔记 > Android > 正文

如何用里面的两个视图刷新SwipeRefreshLayout

如何解决《如何用里面的两个视图刷新SwipeRefreshLayout》经验,为你挑选了1个好方法。

我已经SwipeRefreshLayout有两个孩子:RecyclerViewLinearLayout 让我不得不定制RecyclerView:

recycler_view.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            // int topRowVerticalPosition = (recyclerView == null || recyclerView.getChildCount() == 0) ? 0 : recyclerView.getChildAt(0).getTop();
            // swipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0);
            if (!defined) {
                toolbarHeight = ll_header.getMeasuredHeight() + 15;
                footerHeight = ll_footer.getMeasuredHeight() + 15;
                defined = true;
            }
            clipToolbarOffset();
            if ((toolbarOffset < toolbarHeight && dy > 0) || (toolbarOffset > 0 && dy < 0)) {
                toolbarOffset += dy;
            }
            if ((footerOffset < footerHeight && dy > 0) || (footerOffset > 0 && dy < 0)) {
                footerOffset += dy;
            }
            onMoved(toolbarOffset, footerOffset);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            // super.onScrollStateChanged(recyclerView, newState);
            if (recyclerView.getAdapter() != null) {
                if (recyclerView.getAdapter().getItemCount() > 0) {
                    int currentPosition = ((RecyclerViewAdapter) recyclerView.getAdapter()).getCurrentPosition();
                    if (currentPosition > limit && currentPosition >= items.size() - 2) {
                        if (!isLoading) {
                            getContent();
                        }
                    }
                }
            }
            LinearLayoutManager llm = (LinearLayoutManager) recyclerView.getLayoutManager();
            if (recyclerView.getAdapter() == null) {
                swipeRefreshLayout.setEnabled(true);
                return;
            }
            swipeRefreshLayout.setEnabled(llm.findFirstCompletelyVisibleItemPosition() == 0);
        }
    });

如何在LinearLayout拉下时启用刷新SwipeRefreshLayout?



1> 小智..:

如果要在LinearLayout上启用SwipeRefresh,则需要将LinearLayout放入ScrollView:


    
        

            // insert layout components here ...

        
    

推荐阅读
php
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有