RecyclerView Item 行高定義無效的BUG
阿新 • • 發佈:2019-01-08
剛開始碰到這問題還莫名其妙的, 於是到網路上搜索了一下.發現也有別的小夥伴跟我出現同樣問題.
根據這篇文章可以得出, 導致RecyclerView出現這種問題的原因是因為我們在RecyclerView的Adapter裡的onCreateViewHolder()方法中不恰當的用了打氣筒
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
MyViewHolder viewHolder = new MyViewHolder(LayoutInflater.from (mContext).inflate(R.layout.item_view, null));
return viewHolder;
}
而正確的用法是
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
MyViewHolder viewHolder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_view, parent, false ));
return viewHolder;
}
重點: inflate(R.layout.item_view, parent, false));