一、現象描述
發現自己寫的RecyclerView的列表在小米手機上顯示異常,每一條的item右側空白會比左側的大,我左右距離設置的是相同的,結果設置item橫向鋪滿,再次運行程序後發現在小米手機上沒有橫向鋪滿屏幕
二、問題解決
更改adapter中的代碼
View.inflate(mContext, mLayoutId, parent)或者View.inflate(mContext, mLayoutId, null)
改爲
LayoutInflater.from(mContext).inflate(mLayoutId, parent, false)
即可解決分機型item橫向沒有鋪滿屏幕問題,
三、問題報錯
java.lang.IllegalStateException: ViewHolder views must not be attached when created.
當我們使用第一種方式View.inflate(mContext, mLayoutId, parent)設置adapter時可能會“爆”以上錯誤,
使用LayoutInflater.from(mContext).inflate(mLayoutId, parent, false)即可解決。