简体   繁体   English

如何防止 RecyclerView 在布局计算后自动滚动

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

相关问题 如何在notifyDataSetChanged之后阻止RecyclerView中的自动滚动? - How to prevent auto scroll in RecyclerView after notifyDataSetChanged? 如何防止recyclerView自动滚动? - how to prevent recyclerView auto scroll? 插入新项目时如何防止recyclerview自动滚动到底部? - how to prevent recyclerview auto scroll to bottom when insert new items? 关于布局计算,如何在RecyclerView中访问ViewHolder - How to access ViewHolder in RecyclerView with regards to layout calculation 布局编辑后,Android RecyclerView Scroll无法正常工作 - Android RecyclerView Scroll not working after Layout edit 如何防止在颤振中打印列表后自动向下滚动 - How to prevent auto scroll down after printing a list in flutter 当使用协调器布局滚动我的recyclerview时,如何提供自动隐藏/显示工具栏? - How can I provide auto-hide/show toolbar, when scroll my recyclerview with coordinator layout? 如何在Recyclerview的滚动条上禁用自动更新? - How to disable auto update on scroll of a recyclerview? 如何实现recyclerview的水平自动滚动 - How to implement horizontal auto scroll of recyclerview 如何在Android中制作Circular recyclerview(带有滚动的布局)? - How to make Circular recyclerview (layout with scroll) in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM