如果要实现以下效果,你首先会想到怎么做呢?
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if(customAdapter.getItemCount() - 1 == position){
return 2;
}else{
return 1;
}
}
});
mRecyclerview.setLayoutManager(gridLayoutManager);
- GridLayoutManager传入spanCount为3
- 最后一个Item占据两个span,其他占据一个span