简体   繁体   English

添加项目时,如何防止recyclerview自动滚动到最后一个项目的位置?

[英]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.

相关问题 添加项目时防止recyclerview刷新项目 - Prevent recyclerview from refreshing items when an item is added 选中复选框后如何将项目移动到最后一个位置? (RecyclerView,ViewHolder) - How to move item to the last position when Checkbox is checked? (RecyclerView, ViewHolder) Recyclerview在滚动时自动更改项目位置 - Recyclerview change item position automatically when scrolling 防止 JTextArea 的背景图像在向下滚动时拉伸 - prevent JTextArea's background image from stretching when getting scrolled down 当我向下滚动时,滚动以在recyclerview中添加项目总是自动显示在顶部 - on scrolled to add items in recyclerview always comes to top automatically when i scroll down Recyclerview:-滚动后选择一项时,将选择多项 - Recyclerview :- Multiple items get selectied when one item selected after scrolled recyclerview中没有添加新项目? - new item is not getting added in recyclerview? 从另一个片段/保存recyclerview位置返回后,如何防止片段刷新recyclerview - How to prevent fragment to refresh recyclerview when after back from another fragment / save recyclerview position 如何保存 RecyclerView 中添加的项目? - How to save items added in RecyclerView? 如何防止在recyclerview中调整项目大小 - how to prevent resizing of items in recyclerview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM