VerticalGridFragment未正确显示Android Leanback

我希望使用 VerticalGridFragment 显示每行中的卡片 . 我跟着这个tutorial并扩展了 VerticalGridFragment 类 . 问题是卡片未完全显示在视图上 . 以下是该视图的屏幕截图:

enter image description here

正如您在上图中所看到的,片段仅占据视图的一小部分 . 这是 onCreate 方法的片段,我将 VerticalGridPresenter 设置为网格预设器:

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

并且活动的布局文件是:

<?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>

我试图按照answer扩展 VerticalGridPresenter . 但是,问题仍然存在 .

我在这做错了什么?我怎样才能解决这个问题?

回答(1)

2 years ago

问题是我使用 ListRow 来持卡并将 ListRow 添加到垂直网格 . 删除 ListRow 后,我按预期工作 .