8

我正在尝试创建一个类似于 Youtube 应用程序的 Android 电视应用程序。我正在使用Sofa库来做到这一点。现在,当我试图在没有焦点的情况下显示单个项目的标题时,问题就来RowsFragmentRowsFragment。以下是将数据集加载到browseFragment的代码

private void loadRowsCustom() {
        adapter = new ArrayObjectAdapter();

        int split = 3;
        int rowsFragmentCount = videoList.size() / split + (videoList.size() % split != 0 ? 1 : 0);

        for (int i = 0; i < rowsFragmentCount; i++) {

            ListRowPresenter lrp = new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE);
            ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(lrp);

            String category = "Category";

            for (int j = 0; j < split && (i * split + j) < videoList.size(); j++) {
                Video[] videos = videoList.get(i * split + j);
                ArrayObjectAdapter rowCollAdapter = new ArrayObjectAdapter(new VideoPresenter());
                rowCollAdapter.addAll(0, Arrays.asList(videos));
                ListRow row = new ListRow(new HeaderItem(videos[0].category),rowCollAdapter);
                rowsAdapter.add(row);
                category = videos[0].category;
            }

            ArrayObjectAdapter fragmentAdapter = new ArrayObjectAdapter();
            RowsSupportFragment rowsSupportFragment = new RowsSupportFragment();
            rowsSupportFragment.setAdapter(rowsAdapter);
            rowsSupportFragment.enableRowScaling(false);
            fragmentAdapter.add(rowsSupportFragment);
            adapter.add(new ListRow(new HeaderItem(category), fragmentAdapter));
        }

        browseSupportFragment.setAdapter(adapter);
        browseSupportFragment.setHeadersState(BrowseSupportFragment.HEADERS_ENABLED);
        browseSupportFragment.setOnSearchClickedListener(searchClickListener);
        browseSupportFragment.setOnItemViewClickedListener(browseClickListener);
        browseSupportFragment.setTitle("Google Videos");
    }

所需的和当前的实现如下面的屏幕截图所示:

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

6

正如 Mayur Kaul 已经提到的,你只需要打电话

mRowsFragment.setExpand(true)

但是在这种情况下,每次onAttachedToWindow(...)调用方法时(请参阅android.support.v17.leanback.app.RowsFragment - ItemBridgeAdapter.AdapterListener mBridgeAdapterListener),您的标题标题无论如何都会被隐藏。

所以最终的解决方案,女巫对我有用,它只是简单地覆盖setExpand()RowsFragment 实现中的方法,如下所示:

@Override
    public void setExpand(boolean expand) {
        super.setExpand(true);
    }
于 2017-05-27T12:18:11.657 回答
2

对于那些面临类似问题的人,我终于设法找到了一个可以给出预期结果的黑客。但为此,您可能需要获取SofaBrowseSupportFragment的源代码或在其中修改以下代码行。我知道它有点hack,但它得到了所需的输出。

对于浏览片段:Notice the mRowsFragment.setExpand(true)

private void showHeaders(boolean show) {
        if (DEBUG) Log.v(TAG, "showHeaders " + show);
        mHeadersFragment.setHeadersEnabled(show);
        setHeadersOnScreen(show);
        setRowsAlignedLeft(!show);
        if (mRowsFragment != null) {
            mRowsFragment.setExpand(true);
        } else if (mCurrentFragment != null && mCurrentFragment instanceof RowsFragment) {
            ((RowsFragment) mCurrentFragment).setExpand(true);
        }
    }

BrowseSupportFragment也一样

private void showHeaders(boolean show) {
        if (DEBUG) Log.v(TAG, "showHeaders " + show);
        mHeadersSupportFragment.setHeadersEnabled(show);
        setHeadersOnScreen(show);
        setRowsAlignedLeft(!show);
        if (mRowsSupportFragment != null) {
            mRowsSupportFragment.setExpand(true);
        } else if (mCurrentFragment != null && mCurrentFragment instanceof RowsSupportFragment) {
            ((RowsSupportFragment) mCurrentFragment).setExpand(true);
        }
    }
于 2016-02-03T10:04:26.860 回答