BrowseFragment 上每个标题的多个 ListRows - Leanback 库 [英] Multiple ListRows for each Header on BrowseFragment - Leanback library

查看:24
本文介绍了BrowseFragment 上每个标题的多个 ListRows - Leanback 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始为我们的应用程序提供 Leanback 支持.根据 UI 要求,我需要为每个标题添加多个列表行,这与 Youtube App 在 Android TV 上所做的完全一样.默认 ListRowPresenter 似乎只呈现一个列表行及其标题.是否有支持多个列表行的演示者?我正在考虑创建一个嵌入在每个项目中的 RowsFragment 的自定义演示者,如果我的方法错误,请纠正我.

解决方案

Leanback 团队最近添加了对 HeaderItem 版本中的多个 ListRow 的支持>24.0.0 库.它允许您提供一个映射到 HeaderItemRowsFragment.你可以在他们的 Leanback 展示中看到一个例子.具体来说,这里 是他们提供示例的文件.

您在 BrowseFragment 中需要一个新的 PageRowFragmentFactory,它指定哪些 Fragment 映射到哪些 HeaderItem.像这样:

 @Override公共片段 createFragment(Object rowObj) {行行 = (Row)rowObj;mBackgroundManager.setDrawable(null);if (row.getHeaderItem().getId() == HEADER_ID_1) {返回新的 SampleFragmentA();} else if (row.getHeaderItem().getId() == HEADER_ID_4) {返回新的 WebViewFragment();}throw new IllegalArgumentException(String.format("Invalid row %s", rowObj));}

您可以让上述方法返回一个 RowsFragment 的实例,现在您将拥有包含多个 ListRowRowsFragment仅映射到一个 HeaderItem.

截至目前,您可以通过 Leanback 24.0.0 版使用您的 gradle 文件中的以下行来访问此优点:

编译'com.android.support:leanback-v17:24.0.0

您可能会收到警告,但现在可以安全地忽略它.

在 Leanback 的 24.0.0 版本中还有很多其他非常酷的东西,比如时髦的过渡动画和更清晰的 API.所有这些都可以在我上面链接的示例项目中找到.还有一个来自 Google I/O 的演讲,其中涵盖了更多新增内容.>

I'm getting started with Leanback support for our app. As per UI requirements I need to add multiple list rows corresponding to each header, it's exactly like what Youtube App does on Android TV. Default ListRowPresenter seems to be rendering only one list row and its header. Is there any presenter that supports multiple list rows? I'm thinking on the lines creating a custom presenter with RowsFragment embedded in each item, correct me if my approach is wrong.

解决方案

The Leanback team has recently added in support for multiple ListRows for one HeaderItem in version 24.0.0 of the library. It allows you to supply a RowsFragment that maps to the HeaderItem. You can see an example of it in their Leanback showcase. Specifically, here is the file where they provide an example.

There is a new PageRowFragmentFactory that you will need in your BrowseFragment which specifies which Fragments map to which HeaderItems. Like so:

    @Override
    public Fragment createFragment(Object rowObj) {
        Row row = (Row)rowObj;
        mBackgroundManager.setDrawable(null);
        if (row.getHeaderItem().getId() == HEADER_ID_1) {
            return new SampleFragmentA();
        } else if (row.getHeaderItem().getId() == HEADER_ID_4) {
            return new WebViewFragment();
        }
        throw new IllegalArgumentException(String.format("Invalid row %s", rowObj));
    }

You can just have the above method return an instance of a RowsFragment and now you'll have the RowsFragment which contains multiple ListRows map to just one HeaderItem.

As of right now you can get access to this goodness through version 24.0.0 of Leanback with the below line in your gradle file:

compile 'com.android.support:leanback-v17:24.0.0

You might get a warning, but for now it can be safely ignored.

There is also a ton of other really cool stuff in version 24.0.0 of Leanback like snazzy transition animations and cleaner APIs. It can all be found in that sample project I linked above. There is also a talk from Google I/O which covers more of the additions.

这篇关于BrowseFragment 上每个标题的多个 ListRows - Leanback 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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