RecyclerView问题小结

2018-05-14  本文已影响12人  trythinking

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);//列表翻转

上一篇 下一篇

猜你喜欢

热点阅读