recyclerview宽高无效
今天在使用Androidx包下的recyclerview的时候,写adapter的时候发现无论里面的item大小如何编写都无法变化大小,统一都是wrap_content,去网上搜索了一下问题,发现是源码的问题。
简单来说,就是将原本的
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_home_reserve,null);
写法转变为
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_home_reserve,parent,false);
写法,具体原因是在重载的时候,如果参数填写null的话,会默认设置为wrap_content,从而导致一些问题。
详细的分析等等请见:
https://www.jianshu.com/p/a2172589aafb