recycleView scrollToPosition 现象
2016-09-23 18:04
1096 查看
如果position对应的view已经显示出来了,那么是不会有滑动现象的
原因?
LinearLayoutManager类中的onLayouthildren方法,约483行
mReverseLayout
Defines if layout should be calculated from end to start.
就是说反过来的布局,默认是false的
// item is not visible.
if (mPendingScrollPositionOffset == INVALID_OFFSET) {
if (getChildCount() > 0) {
// get position of any child, does not matter
int pos = getPosition(getChildAt(0));
anchorInfo.mLayoutFromEnd = mPendingScrollPosition < pos
== mShouldReverseLayout;
}
就是说,如果第一个visible的position 是6,而我要移动到的是第10个,
如果不是反过来布局的,那么就从end开始
so, 调用带有offset的方法,但是参数传0,就可以了
最后欢迎关注我的微信公众号:云端看大地
原因?
LinearLayoutManager类中的onLayouthildren方法,约483行
updateAnchorInfoForLayout(recycler, state, mAnchorInfo);
if (updateAnchorFromPendingData(state, anchorInfo)) { if (DEBUG) { Log.d(TAG, "updated anchor info from pending information"); } return; }
mReverseLayout
Defines if layout should be calculated from end to start.
就是说反过来的布局,默认是false的
// item is not visible.
if (mPendingScrollPositionOffset == INVALID_OFFSET) {
if (getChildCount() > 0) {
// get position of any child, does not matter
int pos = getPosition(getChildAt(0));
anchorInfo.mLayoutFromEnd = mPendingScrollPosition < pos
== mShouldReverseLayout;
}
就是说,如果第一个visible的position 是6,而我要移动到的是第10个,
如果不是反过来布局的,那么就从end开始
so, 调用带有offset的方法,但是参数传0,就可以了
补充:2017-1-4
如果activity是RelativeLayout,recyclerVuiew会两次调用child.Layout,并且当最后一页的时候,例如显示了3的一半,4,5,(6未显示完全),scrollToPositionWithOffset这个时候如果要滚动到3,理想中的位置是3在最顶部,然而,如果recycler below 一个view A,那么,3不会滚动到顶部,而是,距离顶部有一个viewA的距离,也就是说距离屏幕顶部有2个viewA的距离,解决办法 把activity由RelativeLayout改为LinearLayout最后欢迎关注我的微信公众号:云端看大地
相关文章推荐
- RecyclerView smoothScrollToPosition的滚动时间
- mRecyclerView.scrollToPosition不起作用
- Android RecyclerView.smoothScrollToPosition()的实现
- - (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPos
- RecyclerView scrollToPosition 无效的问题
- RecyclerView通过manager.smoothScrollToPosition()来改变滑动速度
- smoothScrollToPositionFromTop girdview 有时滚动到指定无效
- RecyclerView调用smoothScrollToPosition() 控制滑动速度
- RecyclerView的setScrollToPositionWithOffset
- adding iphone touches to unitygui scrollview
- 当PullToRefreshScrollView里面嵌套ListView
- 使用开源的PullToRefreshScrollView scrollTo和scrollby遇到的问题
- 开源项目PullToRefresh详解(三)——PullToRefreshScrollView
- java.lang.NoSuchMethodError: smoothScrollToPositionFromTop for Froyo ListView?
- PullToRefreshScrollView+GridView,实现向下滑动中隐藏自定义Action布局
- 下拉刷新之ScrollView--PullToRefreshScrollView
- viewgroup scrollTo、scrollBy、getScrollX、getScrollY这4个方法的含义
- uitableview scrollRectToVisible(要显示的区域)
- iOS: How To Make AutoLayout Work On A ScrollView
- iOS: UIScrollViewDelegate Protocol的方法scrollViewDidScrollToTop: