Vertical list like android phones in android tv leanback

帅比萌擦擦* 提交于 2020-01-06 05:23:09

问题


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 ?

Refer below image for more clarification on ui requirement.

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 ?


回答1:


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));


来源:https://stackoverflow.com/questions/58609475/vertical-list-like-android-phones-in-android-tv-leanback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!