如何始终在RowsFragment中显示标题 [英] how to always show headers in RowsFragment
问题描述
我正在尝试创建一个类似于Youtube应用程序的Android电视应用程序.并且我正在使用
如Mayur Kaul所述,您只需要致电
mRowsFragment.setExpand(true)
但是在这种情况下,每次将调用 onAttachedToWindow(...)
方法时(请参见 android.support.v17.leanback.app.RowsFragment
-ItemBridgeAdapter.AdapterListener mBridgeAdapterListener
),标题标题仍然会被隐藏.
最后的解决方案,巫婆为我工作,它只是在您的RowsFragment实现中简单地重写 setExpand()
方法,如下所示:
@Overridepublic void setExpand(boolean expand){super.setExpand(true);}
I'm trying to create an Android tv application similar to the Youtube application. and I am using the Sofa library to do that. Now the problem comes when I am trying to show the headers for individual items in the RowsFragment
even when the RowsFragment
doesn't have a focus. following is the code for loading the dataset into 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");
}
The required and the current implementation is described as in the screenshots below:
As Mayur Kaul already mentioned, u just need to call
mRowsFragment.setExpand(true)
But in this case everytime when onAttachedToWindow(...)
method would be called (see android.support.v17.leanback.app.RowsFragment
- ItemBridgeAdapter.AdapterListener mBridgeAdapterListener
), your header titles anyway would be hidden.
So final solution, witch worked for me it's just simply override setExpand()
method in your RowsFragment implementation like below:
@Override
public void setExpand(boolean expand) {
super.setExpand(true);
}
这篇关于如何始终在RowsFragment中显示标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!