gpt4 book ai didi

android - 如何始终在 RowsFragment 中显示标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:53:44 25 4
gpt4 key购买 nike

我正在尝试创建一个类似于 Youtube 应用程序的 Android 电视应用程序。我正在使用 Sofa库来做到这一点。现在,当我试图显示 RowsFragment 中各个项目的 header 时,即使 RowsFragment 没有焦点,问题也来了。以下是将数据集加载到 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");
}

所需的和当前的实现在下面的屏幕截图中进行了描述:

enter image description here

enter image description here

最佳答案

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

mRowsFragment.setExpand(true)

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

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

@Override
public void setExpand(boolean expand) {
super.setExpand(true);
}

关于android - 如何始终在 RowsFragment 中显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35151717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com