在RecyclerView布局使用CardView不能match_parent

图片描述

图片描述
结果跑到程序里是这样的::

不能定义宽高,不能让它的宽match,怎么回事?

阅读 6.1k
5 个回答

OnCreateViewholder里这么写:
Inflater.inflate(r.layout.xxx,container,false).

你的adapter,oncreateviewholder代码贴出来,看inflate的时候参数是3个不

看下你的recyclerview的宽度设置

新手上路,请多包涵

之前遇过,View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.content_item,parent,false); 改成这样绑定cardview就可以了,我是这么解决的,希望对你有没有帮助
http://m.blog.csdn.net/article/details?id=51108390

你可以尝试给它(inflate,Item布局的view)设置layoutparams

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(DensityUtils.dp2px(mContext,7),DensityUtils.dp2px(mContext,7),DensityUtils.dp2px(mContext,2),DensityUtils.dp2px(mContext,18));                   

inflate.setLayoutParams(layoutParams);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题