本文共 1297 字,大约阅读时间需要 4 分钟。
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);
这样就好了
转载地址:http://jutli.baihongyu.com/