问题
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