答案 0 :(得分:2)
您可以在此link中查看我的答案。使用Recyclerview
和GridLayoutManager
。在RecyclerAdapter
中定义两种类型。
答案 1 :(得分:0)
创建2个视图持有者并返回您的ViewType
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position)) {
return TYPE_HEADER;
}
return TYPE_ITEM;
}
并在onCreateViewHolder中获取该viewType并像这样使用它
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View headerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_recycler_view_header, parent, false);
return new ViewHolderHeader(headerView);
} else if (viewType == TYPE_ITEM) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_recycler_view_item, parent, false);
ViewHolderItem viewHolder = new ViewHolderItem(itemView);
return viewHolder;
}
throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
}