美文网首页
RecyclerView问题小结

RecyclerView问题小结

作者: trythinking | 来源:发表于2018-05-14 16:47 被阅读12次

1、setAdapter后没有执行onCreateViewHolder、onBindViewHolder、getItemCount

LinearLayoutManager mLayoutmanager =new LinearLayoutManager(this);

mRecyclerView.setLayoutManager(mLayoutmanager);

原因是没有给 RecyclerView 设置布局管理器

2、定位滚动

smoothScrollBy(int dx,int dy)

smoothScrollToPosition(int position)

3、获取第一个和最后一个可见item的位置

int firstVisibleItemPosition =mLayoutmanager.findFirstVisibleItemPosition();

int lastVisibleItemPosition =mLayoutmanager.findLastVisibleItemPosition();

4、RecyclerView 的 getChildAt(int index) 获取某个位置的item为null,采用

mLayoutmanager.findViewByPosition(int position)

5、列表倒序排列

mLayoutmanager.setStackFromEnd(true);//列表在底部开始展示,反转后由上面开始展示

mLayoutmanager.setReverseLayout(true);//列表翻转

相关文章

网友评论

      本文标题:RecyclerView问题小结

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