Uday Ramjiyani
Uday Ramjiyani

Reputation: 1447

Vertical list like android phones in android tv leanback

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 ?

enter image description here

Upvotes: 1

Views: 1422

Answers (1)

Breiby
Breiby

Reputation: 552

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

Upvotes: 4

Related Questions