//根据数据类型自定义SectionProvider, 并实现getSectionImpl()方法, 返回Section对象。 DataSelectionProvider sectionProvider = new DataSelectionProvider(dataList); //默认的SectionPainter, 可实现SectionPainter接口进行自定义效果绘制 TextSectionPainter sectionPainter = new TextSectionPainter.Builder(this) .setSectionBarColor(0xffffacac) .setDividerColor(0xffff8888) .setTextColor(0xffffffff) .setTextSize(dip2px(16)) .setSectionBarHeight(dip2px(32)) .setDividerHeight(1) .build(); //创建ItemDecoration SectionItemDecoration decoration = new SectionItemDecoration(sectionProvider, sectionPainter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(decoration); recyclerView.setAdapter(new Adapter(dataList));
请发表评论