美文网首页
RecyclerView控件布局的"match_par

RecyclerView控件布局的"match_par

作者: 路过麦田 | 来源:发表于2016-03-10 22:20 被阅读2673次

在使用RecyclerView控件时发现在item的布局文件中设置宽度为match_parent无效,在Android Studio中预览布局一点问题没有,但是真机运行后发现item的宽度表现为wrap_content,检查过好几遍布局文件,应该是没问题的,所以最可能出现问题的地方应该就是在inflate布局文件的时候,经过测试,发现在实例化布局的时候不能采取如下的方式:

View view = LayoutInflater.from(context).inflate(context, R.layout.new_chat_item_text, null);

需要将其改为:

View view = mInflater.from(context).inflate(R.layout.new_chat_item_text, parent, false);

改正后item布局的match_parent属性就起作用了。

相关文章

网友评论

      本文标题:RecyclerView控件布局的"match_par

      本文链接:https://www.haomeiwen.com/subject/stptlttx.html