RecyclerView--GridLayoutManager设置某个item占据的列数

    /**
     * 将RecyclerView的网格布局中的某个item设置为独占一行、只占一列,只占两列、等等
     * @param gridLayoutManager
     */
    private void setSpanCount(GridLayoutManager gridLayoutManager){
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            int type = getItemViewType(position);
            if (type == TYPE_NORMAL_ITEM) {
                return 1;//只占一行中的一列,
            } else {
                return gridLayoutManager.getSpanCount();//独占一行
            }
        }
    });
}

你可能感兴趣的:(RecyclerView)