setSpanSizeLookup 方法作用就返回不同的列表
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int i) {
int stringLenth = item.getValues().get(i).getName().length();
if (3 < stringLenth && stringLenth < 6) {
return 2;
} else if (5 < stringLenth && stringLenth < 9) {
return 2;
} else if (8 < stringLenth && stringLenth < 12) {
return 2;
} else if (12 < stringLenth) {
return 2;
} else {
return 1;
}
}
});
解决方法 :把 setAdapter 写在setLayoutManager上面 就好了
mRecycler.setAdapter(newStoreSpecificationTwoAdapter(R.layout.item_storespecificationtwo_layout,listData));
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int i) {
int stringLenth = item.getValues().get(i).getName().length();
if (3 < stringLenth && stringLenth < 6) {
return 2;
} else if (5 < stringLenth && stringLenth < 9) {
return 2;
} else if (8 < stringLenth && stringLenth < 12) {
return 2;
} else if (12 < stringLenth) {
return 2;
} else {
return 1;
}
}
});
mRecycler.setLayoutManager(gridLayoutManager);
这样就好了
在Android开发中遇到RecyclerView的setSpanSizeLookup方法未被调用的问题,通过调整代码顺序,将setAdapter写在setLayoutManager之前,可以成功解决问题。
4885





