从中间项滚动 recyclerview [英] Scrolling recyclerview from the middle item

查看:32
本文介绍了从中间项滚动 recyclerview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android TV 开发应用程序,我有一个垂直的 RecyclerView,当我使用 DPAD 控件滚动 RecyclerView 时,RecyclerView 在到达最后一个可查看项目时向下滚动,然后滚动.

I am developing app for Android TV and I have a vertical RecyclerView, when I scroll the RecyclerView using the DPAD control the RecyclerView scroll down when I get to the last viewable item and then it scroll.

当我使用 DPAD 滚动时,焦点是否会始终停留在 recyclerview 的中心,并且只有当我到达 recyclerview 的最后一个项目时,焦点才会移动到最后一个项目.

Is there away that the focused item will always stay in the center of the recyclerview while I scroll using the DPAD and only when I get to the last item of the recyclerview the focus will go until the last item.

在 RecyclerView 中有一个内置选项似乎很简单,但我找不到答案!!!

It seems simple enough to have a build in option inside the RecyclerView but I can't find an answer!!!

谢谢!

推荐答案

您可以使用 SnapHelper 可以垂直或水平捕捉项目.例如:将实例附加到 recyclerView 中,如下所示:

You can use SnapHelper which can snap the item either vertically or horizontally. For example: attach the instance the the recyclerView like this:

LinearSnapHelper snapHelper  = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);

这里有更多信息:

https://blog.mindorks.com/using-snaphelper-in-recyclerview-fc616b6833e8

这篇关于从中间项滚动 recyclerview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆