【问题标题】:How to prevent a recyclerview from getting automatically scrolled to the last item's position when items are added to it?添加项目时,如何防止recyclerview自动滚动到最后一个项目的位置?
【发布时间】:2019-05-11 09:39:08
【问题描述】:

我知道我们可以使用 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 中

【问题讨论】:

    标签: java android user-interface


    【解决方案1】:

    我只是想出了解决方案,我只需要将 android:descendantFocusability="blocksDescendants" 放在 NestedScrollView 内的布局上,这有助于我摆脱这个问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多