垂直列表,如 android tv 中的 android 手机 [英] Vertical list like android phones in android tv leanback

查看:35
本文介绍了垂直列表,如 android tv 中的 android 手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的垂直列表(一行中的单列),它只能垂直滚动,不能水平滚动.我如何使用 Leanback 在 android 电视上实现这一点?

I want to create a simple vertical list (single column in a row), which is only scrollable vertically not horizontally. How do i achieve this on android tv using leanback ?

有关 ui 要求的更多说明,请参阅下图.

Refer below image for more clarification on ui requirement.

我尝试使用 VerticalSupportFragment,但行项目没有跨越全宽,我也尝试更改样式和演示者.

I tried using VerticalSupportFragment, but a row item doesn't spans to a full width, tried changing styles and presenter also.

提前致谢,有什么办法可以实现吗?

Thanks in advance, is there any way to achieve this ?

推荐答案

如果你使用 VerticalGridSupportFragment 你可以这样设置列数:

If you use a VerticalGridSupportFragment you can set the number of columns like this:

VerticalGridPresenter presenter = new VerticalGridPresenter();
gridPresenter.setNumberOfColumns(1);
setGridPresenter(gridPresenter);

这有效地为您提供了一个垂直列表.然后,您可以在行项目演示器中编辑视图的宽度.例如,如果您希望视图水平填充屏幕,您可以执行以下操作:

This effectively gives you a vertical list. Then you can edit the width of the view in your row item presenter. For example if you want the view to fill the screen horizontally you could do something like:

int height = 42;
int width = getContext().getResources().getDisplayMetrics().widthPixels;
view.setLayoutParams(new LayoutParams(width, height));

这篇关于垂直列表,如 android tv 中的 android 手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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