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

时间:2019-05-11 09:39:09

标签: java android user-interface

我知道我们可以使用方法notifyDataSetChanged()将新元素添加到recyclerview并更新视图,但是我需要平滑过渡。

当我尝试使用带有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);
}

此代码使它自动滚动到recyclerview的最后一项。关于此问题的另一件事是它仅在某些时候发生。我需要提及的是,我的recyclerview位于Nestedscrollview中

1 个答案:

答案 0 :(得分:0)

我只是想出解决方案,我只需要在NestedScrollView内的布局上放置android:descendantFocusability="blocksDescendants",就可以解决这个问题。

感谢这篇文章帮助我摆脱了这个问题 NestedScrollView scroll down itself when content is fills