Search code examples
javaandroidandroid-tvleanback

VerticalGridFragment is not displayed properly Android Leanback


I want show to cards in each row using a VerticalGridFragment. I followed this tutorial and extended the VerticalGridFragment class. The problem is the cards are not displayed fully on the view. Here is the screenshot of the view:

enter image description here

As you can see in the above image, the fragment is occupying only a small portion of the view. Here is a snippet of the onCreate method where I set the VerticalGridPresenter as the grid presetner:

public class VideoFragment extends VerticalGridFragment {
    private static final String TAG = VideoFragment.class.getSimpleName();

    public static final String CAT = "Category";
    private ArrayObjectAdapter mRowsAdapter;
    private PicassoBackgroundManager mBackgroundManager;
    private List<Movie> mItems;
    private VideosActivity mActivity;
    private Category mCategory;
    private Section mSection;

    private static final int COLUMNS = 4;
    private static final int ZOOM_FACTOR = FocusHighlight.ZOOM_FACTOR_MEDIUM;

    @Override
    public void onCreate(Bundle savedInstance) {
        Log.i(TAG, "onActivityCreated");
        super.onCreate(savedInstance);

        VerticalGridPresenter presenter = new VerticalGridPresenter();
        presenter.setNumberOfColumns(COLUMNS);
        setGridPresenter(presenter);



        setupEventListeners();
        setUpUIElements();

        getMovieItems();


        mActivity = (VideosActivity)getActivity();
        mBackgroundManager = new PicassoBackgroundManager(getActivity());
        mBackgroundManager.updateBackgroundWithDelay();
    }
}

And the layout file for the activity is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >

    <fragment
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools" android:id="@+id/video_browse_fragment"
        android:name="app.com.tsehaytv.ui.VideoFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:deviceIds="tv"
        tools:ignore="MergeRootFrame" />

</RelativeLayout>

I tried to extend the VerticalGridPresenter as per this answer. However, the issue still persists.

What am I doing wrong here? How can I fix this?


Solution

  • The issue was I was using a ListRow to hold the cards and added the ListRow to the vertical grid. After removing the ListRow, I works as expected.