使用RecyclerView 时,在xml文件中设置宽度match_parent无效。

 View view = mInflater.from(mContext).inflate(R.layout.item_recycler_view, parent, false);

对于:inflate

 public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
if (DEBUG) System.out.println("INFLATING from resource: " + resource);
XmlResourceParser parser = getContext().getResources().getLayout(resource);
try {
return inflate(parser, root, attachToRoot);
} finally {
parser.close();
}
}

即调用了:

public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot) 

其方法对于理解后两个参数作用的代码:

 ViewGroup.LayoutParams params = null;  

 if (root != null) {
if (DEBUG) {
System.out.println("Creating params from root: " +
root);
}
// Create layout params that match root, if supplied
params = root.generateLayoutParams(attrs);
if (!attachToRoot) {
// Set the layout params for temp if we are not
// attaching. (If we are, we use addView, below)
temp.setLayoutParams(params);
}
}

调用其方法:

1、传入了ViewGroup root参数,则会从root中得到由layout_width和layout_height组成的LayoutParams

2、如果attachToRoot设置为false的话,就会对我们加载的视图View设置该LayoutParams。

所以RecyclerView 如果采用平常方式去inflate,宽度不会显示全,设置layout_width="match_parent" 无效。

RecyclerView android:layout_width="match_parent" 无效的更多相关文章

  1. RecyclerView中设置match_parent无效;

    在RecyclerView中宽度设置了match_parent,但是效果和wrap_content一样: 说下解决方法: 1.这样子写,match_parent没有效果: View v = View. ...

  2. 关于设置android:imeOptions属性无效的解决办法

    在对Android的EditText控件进行设置时,经常会限定一下输入法的属性,设置右下角为完成或者搜索等,一般都会想到android:imeOptions属性,但是仅仅这么设置通常是无效的,还要搭配 ...

  3. RecyclerView android

    RecyclerView是用来替代ListView.GridView的一个牛掰的控件.用起来更灵活,还能实现线性布局(横向.纵向).网格布局.瀑布流等美观的UI. 在使用RecyclerView时候, ...

  4. viewpager的layout_width="wrap_content"无效问题

    在viewpager当中直接使用layout_width="wrap_content"是无效的,扩展了一下.解决这个问题. package com.soulagou.ui; imp ...

  5. android:layout_height、android:layout_width、android:height、android:width的关系与区别

    一直一来对android:layout_height.android:layout_width.android:height.android:width这几个属性的关系有些不理解,既然有了androi ...

  6. [转]Android中的android:layout_width和android:width

      android:width 其实是定义控件上面的文本(TextView) 的宽度,当然这个宽度也是和 android:layout_width 配合起来作用的,如果 android:layout_ ...

  7. Android中的android:layout_width和android:width

    最近在看android的东西,发现很多和web前台的东西一样(思想).只是看到很多属性的写法和前台有差别,刚刚看到这样的属性: android:width 其实是定义控件上面的文本(TextView) ...

  8. 【原创】Android selector选择器无效或无法正常显示的一点研究

    想将LinearLayout作为一个按钮,加上一个动态背景,按下的时候,背景变色,这个理所当然应该使用selector背景选择器来做: <LinearLayout android:id=&quo ...

  9. android优化 清除无效代码 UCDetector

    android下优化 清除无效 未被使用的 代码 UCDetector 官方下载地址:http://www.ucdetector.org/index.html UCDetector  是 eclips ...

随机推荐

  1. location url 反向代理到来机的其它端口 gitlab

    location /nexus { proxy_pass http://127.0.0.1:8081/nexus; } [root@GitMaven conf]# pwd /var/opt/gitla ...

  2. ASP.NET Web API 中的异常处理(转载)

    转载地址:ASP.NET Web API 中的异常处理

  3. Android 注解工具 ButterKnife

    Butter Knife 是 Android 视图字段和方法绑定,使用注解处理来生成样板代码. 主要特性: 在字段使用 @FindView消除findViewById调用 使用 @FindViews在 ...

  4. Delphi开发中各种文件扩展名代表什么文件

    暂时就遇到了以下这几种,以后遇到再进行补充 .DPR Delphi Project文件,打开这个文件,就会打开所有的编程的代码文件.包含了Pascal代码 .PAS Pascal文件,Pascal单元 ...

  5. VC++6.0使用OpenGL前的配置(必看)

    要在VC++6.0中使用opengl,需要配置一下环境设置. 具体需要两步: 1.加入一个头文件,两个lib文件,两个dll文件,放在合适位置. 2.配置一下vc++6.0的Project Setti ...

  6. [LeetCode] Gas Station

    Recording my thought on the go might be fun when I check back later, so this kinda blog has no inten ...

  7. 豆瓣的账号登录及api操作

    .douban.php <?php /** * PHP Library for douban.com * * @author */ class doubanPHP { function __co ...

  8. VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网的三种方法介绍

    转自:http://www.jb51.net/network/98820.html 如何真正的实现VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网   环境:WIN7旗舰版,台式机,U盘无 ...

  9. winedt打开.tex文件时会出现reading error,看不到任何文字

    winedt打开.tex文件时会出现reading error,然后看不到任何文字.   解决办法:先打开空白的winedt,然后点击open,找到该.tex文件,将文件名右侧的 default 改为 ...

  10. javascript中的true和false

    今天遇到一个问题,执行下面的代码返回true还是false?请说明理由 console.log([] == ![]) 在浏览器中运行了一下,发现结果是true.为什么会这样呢?于是查找了相关的资料. ...