[英]How to prevent a recyclerview from getting automatically scrolled to the last item's position when items are added to it?
I understand that we can use the methods notifyDataSetChanged() to add new elements to the recyclerview and update the view, but I need the transition to be smooth. 我知道我们可以使用方法notifyDataSetChanged()向recyclerview添加新元素并更新视图,但是我需要平滑过渡。
When I tried using a Transition with a LinearInterpolator, I could achieve the effect, but the scroll automatically jumps to the last position of the updated list and I need to avoid that. 当我尝试将LinearInterpolator与Transition一起使用时,可以达到这种效果,但是滚动会自动跳到更新列表的最后一个位置,因此需要避免这种情况。
moreButtonClicked(){
viewMore.setVisibility(View.GONE);
rcAdapter.moreClicked = true;
rcAdapter.notifyDataSetChanged();
Transition changeBounds = new ChangeBounds();
changeBounds.setDuration(3000);
changeBounds.setInterpolator(new LinearInterpolator() );
TransitionManager.beginDelayedTransition(myCityList,changeBounds);
}
This code makes it autoscroll to the last item of the recyclerview. 此代码使其自动滚动到recyclerview的最后一项。 The other thing about this problem is that it happens only sometimes.
关于此问题的另一件事是它仅在某些时候发生。 I need to mention that my recyclerview is within a Nestedscrollview
我需要提及的是,我的recyclerview位于Nestedscrollview中
I just figured the solution, I just needed to put android:descendantFocusability="blocksDescendants"
on the layout inside the NestedScrollView which helped me get rid of this issue. 我只是想出解决方案,我只需要将
android:descendantFocusability="blocksDescendants"
放在NestedScrollView内的布局上,就可以解决这个问题。
Thanks to this post which helped me get rid of this issue NestedScrollView scroll down itself when content is fills 感谢这篇文章帮助我摆脱了这个问题,当内容填充时NestedScrollView向下滚动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.