我正在尝试创建一个ListView,其标题是水平滚动的RecyclerView,但是我遇到了一些问题。
以下是我正在尝试创建此场景的片段代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.viewLayoutResId = isGrid ? R.layout.fragment_deals_grid : R.layout.fragment_deals_list;
this.listResId = isGrid ? R.id.deal_grid : R.id.deal_list;
View view = inflater.inflate(viewLayoutResId, container, false);
progressBar = (ProgressBar) view.findViewById(R.id.deal_progress);
mListView = (AbsListView) view.findViewById(listResId);
//HEADER CREATION HERE
RecyclerView header = (RecyclerView) inflater.inflate(R.layout.fragment_deals_display_header, null);
header.setAdapter(new DealsDisplayCategoriesAdapter(Deal.CATEGORIES));
header.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
header.setHasFixedSize(true);
if(mListView instanceof ListView) {
ListView listView = (ListView) mListView;
listView.addHeaderView(header, null, false);
}else if(mListView instanceof GridViewWithHeaderAndFooter) {
GridViewWithHeaderAndFooter gridView = (GridViewWithHeaderAndFooter) mListView;
gridView.addHeaderView(header, null, false);
}else{
Log.v("DEALDISPLAY", "no header :: "+mListView);
}
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
return view;
}
问题在于RecyclerView标头没有显示出来。它看起来是空的。
我已经测试了一些案例,试图缩小问题所在的范围:
总之,添加一个不是RecyclerView的标头可以正常工作,因此标头不能成为问题。在其他地方充气RecyclerView是有效的,所以RecyclerView不是问题所在。
我做错了什么?我想做什么甚至可能?
编辑:
fragment_deals_display_header.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/deals_display_header_recycler">
</android.support.v7.widget.RecyclerView>