我尝试在滚动到 recyclerView 底部时实现加载更多
当我的 XML 只有 recyclerView 时它可以工作,但当我将它放入滚动视图和 setNestedScrollingEnabled(false) 时它不起作用
" Requirement "
- The orange area is static layout
- The green area is dynamic items
and when i scoll to bottom orange area must be scroll down too
mAdapter = new RecyclerViewCommentAdapter(commentList, userInformationList);
mRecyclerViewComment = (RecyclerView) rootView.findViewById(R.id.recyclerViewComment);
mRecyclerViewComment.setNestedScrollingEnabled(false);
mRecyclerViewComment.setHasFixedSize(true);
mRecyclerViewComment.setItemViewCacheSize(30);
mRecyclerViewComment.setDrawingCacheEnabled(true);
mRecyclerViewComment.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
mLayoutManager = new LinearLayoutManager(mContext);
mRecyclerViewComment.setLayoutManager(mLayoutManager);
mRecyclerViewComment.setItemAnimator(new DefaultItemAnimator());
mRecyclerViewComment.setAdapter(mAdapter);
// Scroll //
mRecyclerViewComment.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
Log.d(getClass().getName(), "dy = " + dy);
if(dy > 0) //check for scroll down
{
visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
Log.d(getClass().getName(), "totalItemCount = " + totalItemCount);
if (loading)
{
if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount && (visibleItemCount + pastVisiblesItems) >= TOTAL_FIRST_LOAD)
{
loading = false;
loadMoreKey();
}
}
}
}
});
}
我尝试调试 'dy' 它总是 0
dy 为 0 因为RecyclerView
不滚动,其内容适合滚动视图。所以,滚动的视图是ScrollView
.
这不是一个特别好的实现,因为所有的观点RecyclerView
同时膨胀,这超出了目的RecyclerView
也就是重用ViewHolders
当用户滚动并动态膨胀视图中的元素以节省内存使用时。
尝试固定高度RecyclerView
并且不要使用wrap_content
or match_parent
in the height
你的财产RecyclerView
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)