博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android setSpanSizeLookup 不被调用Log 也不走
阅读量:4204 次
发布时间:2019-05-26

本文共 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/

你可能感兴趣的文章