【问题标题】:Port Recycler view created for mobile app to Android TV supporting Dpad controls为支持 Dpad 控件的 Android TV 的移动应用程序创建的 Port Recycler 视图
【发布时间】:2017-01-18 12:14:19
【问题描述】:

我目前正在尝试将 Android 移动应用程序移植到 Android TV。我有一个似乎在我的 Android TV 应用程序中正确显示的 RecyclerView。但我似乎无法使用 dpad 控件在 RecyclerView 内导航。 P.S 我已经尝试过以下线路。找不到其他任何东西

        android:descendantFocusability="afterDescendants"

还建议对电视应用使用回收站视图吗?

我还阅读了 developer.android.com 上 TV 应用程序的完整架构,并查看了他们的示例项目,但发现 recycler view 无处可去。

【问题讨论】:

  • 使 recyclerview 元素具有焦点
  • 我添加了这一行 android:descendantFocusability="afterDescendants" not working
  • 回收视图的children必须是可聚焦的。
  • 还添加了 android:focusable="true" 到 recylerview 项目。没有运气
  • 如果您能提供您的问题领域的代码示例会有所帮助

标签: android android-recyclerview android-tv leanback d-pad


【解决方案1】:

正如@ULazdins 所说,您可以尝试使您的RecyclerView 具有焦点。使用 d-pad 导航时,您可以参考此 workaround bugRecycleView 焦点滚动。

正如我从源代码中看到的那样,问题是因为GridLayoutManager 使用LinearLayoutManageronFocusSearchFailed() 实现,当焦点接近RecyclerView 的内边界时调用它。 LinearLayoutManager 的实现只提供第一个/最后一个(取决于滚动方向)元素。因此焦点跳转到新行的第一个/最后一个元素。

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2021-01-27
    • 2017-09-02
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多