我正在尝试创建一个类似于Youtube应用程序的Android电视应用程序。我正在使用Sofa库来做到这一点。现在,当我试图显示RowsFragment
中各个项目的标题时,问题就来了,即使RowsFragment
没有焦点也是如此。以下是将数据集加载到browserFragment中的代码
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");
}
所需的和当前的实现如下面的屏幕快照所示:
最佳答案
正如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);
}