关于RecyclerView 就不多说 ,鸿翔大神已经写的非常详细了.
先上图,主要实现效果(又有水平布局,又有垂直布局):
直接上关键代码:
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext() ,2);
//todo 这个属性很重要,可以直接实现上图的效果
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup(){
@Override
public int getSpanSize(int position) {
if(position % 3 == 0) return 2;
return 1;
}
});
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(adapte);
就是这样, so easy!有问题,欢迎留言!