[英]How to prevent RecyclerView to auto scroll after layout calculation
I have a recycler view that has a horizontal linear layout manager, it has the strange behaviour of auto scroll to the first item when I'm scrolling it for the first time.我有一个具有水平线性布局管理器的回收器视图,当我第一次滚动它时,它具有自动滚动到第一项的奇怪行为。 Do you have any ideas on how to fix that?
你对如何解决这个问题有什么想法吗?
I've already tried to use StaggeredLinearLayout, also tried to use fixed values for width and height, I tried to use android:descendantFocusability="blocksDescendants" also without success.我已经尝试使用 StaggeredLinearLayout,也尝试使用固定的宽度和高度值,我尝试使用 android:descendantFocusability="blocksDescendants" 也没有成功。 So I ran out of ideas on how to fix it.
所以我用完了关于如何修复它的想法。
<android.support.v7.widget.RecyclerView
android:id="@+id/bigItemsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin_small"
android:layout_marginBottom="@dimen/margin_normal"
android:clipToPadding="false"
android:nestedScrollingEnabled="false"
app:paddingInner="@dimen/margin_normal" />
I'd like to it not auto scroll, it uses an adapter with fixed items, so I don't need to call notify on data changed, it only happens once when I scroll to the next item.我想要它不是自动滚动,它使用带有固定项目的适配器,所以我不需要在数据更改时调用通知,它只在我滚动到下一个项目时发生一次。 After this auto scroll, it stops happening.
在此自动滚动后,它停止发生。
From the info above it's hard to tell what the problem is, but calling notifyDataSetChanged() when scrolling (if i understood you right) sounds like something you don't wanne do.从上面的信息很难判断问题是什么,但是在滚动时调用 notifyDataSetChanged() (如果我理解正确的话)听起来像是你不想做的事情。
For example, if you scroll to item 1 and call notifyDataSetChanged.例如,如果您滚动到项目 1 并调用 notifyDataSetChanged。 It will trigger a refresh and your recyclerView will scroll back to the first item.
它将触发刷新,您的 recyclerView 将滚动回第一项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.