RecyclerView scrollToPosition 无效的问题


RecyclerView是个比较蛋疼的控件,给我的第一感觉就是竟然连OnItemClick都没有,


当然,网上有很多的解决方法,可以自己实现。


然而今天,在用到这个控件时,又遇到了个奇葩的问题,


使用过程中,发现 scrollToPosition() 和 smoothScrollToPosition()  都无效,


翻了下熊掌古狗,在stackoverflow看到很多也有遇到这种情况:

http://stackoverflow.com/questions/26580723/how-to-scroll-to-the-bottom-of-a-recyclerview-scrolltoposition-doesnt-work

http://stackoverflow.com/questions/27819507/recyclerview-scrolltoposition-not-trigger-scrolllistener

http://stackoverflow.com/questions/30845742/smoothscrolltoposition-doesnt-work-properly-with-recyclerview




在最后一篇,终于找到了能用的方法,scrollToPositionWithOffset(int, int),但效果不是很理想,没有平滑滚动,而是直接生硬地移到了指定位置。


mLayoutManager = mRecyclerView.getLayoutManager();
mLayoutManager.scrollToPositionWithOffset(pos, 0);


更新:


今天找到原因,没有滚动是因为 要滚动到的位置,已经在屏幕里面了,这时候是不滚动的,

只有要滚到的位置没有在屏幕上,才会滚动。


解决方法可以参考这里:

http://blog.csdn.net/tyzlmjj/article/details/49227601



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值