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.
Leanback 团队最近添加了对多个ListRow
为一HeaderItem
在版本中24.0.0
图书馆的。它允许您提供RowsFragment
映射到HeaderItem
。你可以在他们的文章中看到一个例子靠背展示 https://github.com/googlesamples/leanback-showcase。具体来说,here https://github.com/googlesamples/leanback-showcase/blob/master/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/page/PageAndListRowFragment.java是他们提供示例的文件。
有一个新的PageRowFragmentFactory
您将需要在您的BrowseFragment
它指定哪些 Fragments 映射到哪个HeaderItem
s。就像这样:
@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));
}
你可以让上面的方法返回一个实例RowsFragment
现在你将拥有RowsFragment
其中包含多个ListRow
s 映射到只有一个HeaderItem
.
从现在开始,您可以通过 Leanback 24.0.0 版本来访问此优点,并在 gradle 文件中添加以下行:
compile 'com.android.support:leanback-v17:24.0.0
您可能会收到警告,但现在可以安全地忽略它。
版本中还有很多其他非常酷的东西24.0.0
Leanback 喜欢时髦的过渡动画和更干净的 API。这一切都可以在我上面链接的示例项目中找到。还有一个Google I/O 大会演讲 https://www.youtube.com/watch?v=QFHIfQy8_Wc其中涵盖了更多的添加内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)