转载自:http://www.jianshu.com/p/675883c26ef2
动态加载数据 并根据加载的数据来进行判断显示样式
核心代码
layoutManager = new GridLayoutManager(this, 2);
rv_myCustom.setLayoutManager(layoutManager);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
String name = tagBeanList.get(position).getTagName();
if (name.length() > 9) {
return 2;//每个item项占据多少个单元格 每行有两个item 默认是
}
return 1; //每个item项占据多少个单元格
}
});
tagAdapter = new TadAdapter(tagBeanList);
rv_myCustom.setAdapter(tagAdapter);