美文网首页
ScrollView嵌套RecyclerView的注意事项

ScrollView嵌套RecyclerView的注意事项

作者: ThrowException | 来源:发表于2017-09-28 10:01 被阅读194次

    好记性不如烂笔记

    滑动冲突

    rvHotProduct.setNestedScrollingEnabled(false); // 解决滑动不顺畅
    rvHotProduct.setHasFixedSize(false); // 解决滑动不顺畅
    rvHotProduct.setFocusable(false); // 防止RecyclerView加载数据的时候抢占焦点,把顶部view遮挡了
    

    自动加载更多

    // 加载更多
            rvHotProduct.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    super.onScrollStateChanged(recyclerView, newState);
                    LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                    // 滚到底部
                    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                        int lastVisibleItemPosition = manager.findLastCompletelyVisibleItemPosition();
                        int totalItemCount = manager.getItemCount();
                        if ((lastVisibleItemPosition + 1) == totalItemCount) {
                            // 加载更多
                            if (!isLastPage) {
                                requestHotProduct(++pageNo);
                            }
                        }
                    }
                }
            });
    

    相关文章

      网友评论

          本文标题:ScrollView嵌套RecyclerView的注意事项

          本文链接:https://www.haomeiwen.com/subject/ezlmextx.html