match_parent宽度不RecyclerView工作 [英] match_parent width does not work in RecyclerView

查看:453
本文介绍了match_parent宽度不RecyclerView工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我RecyclerView和项目已match_parent宽度,但其结果是:

 <查看
    类=android.support.v7.widget.RecyclerView
    机器人:layout_width =match_parent

和项目:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
的xmlns:FAB =htt​​p://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / ll_itm
机器人:方向=横向
机器人:layout_width =match_parent

全:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
的xmlns:FAB =htt​​p://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / ll_itm
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:weightSum =100
机器人:重力=右
>
<按钮
    机器人:layout_width =0dp
    机器人:layout_weight =15
    机器人:layout_height =FILL_PARENT
    机器人:文字=ملاحظات
    机器人:ID =@ + ID /键/><的LinearLayout
    机器人:layout_width =0dp
    机器人:layout_height =FILL_PARENT
    机器人:layout_weight =20
    机器人:比重=中心
    >
    <的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向
        >        < com.getbase.floatingactionbutton.FloatingActionButton
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            晶圆厂:fab_plusIconColor =#ff56ff83
            FAB:fab_colorNormal =@彩色/ d_red
            FAB:fab_color pressed =#ff5c86ff
            FAB:fab_size =迷你
            FAB:fab_icon =@绘制/ ic_remove_white
            机器人:ID =@ + ID / fab_rmv/>
        < esfandune.ir.elmikarbordiardakan.other.CustomTxtView
            机器人:layout_weight =25
            机器人:layout_width =0dp
            机器人:layout_height =FILL_PARENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=0
            机器人:重力=右| center_vertical
            机器人:ID =@ + ID / txt_takhir_itm/>
        < com.getbase.floatingactionbutton.FloatingActionButton
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT
            FAB:fab_plusIconColor =@彩色/ colorprimarylight
            FAB:fab_colorNormal =@彩色/ colorprimarydark
            FAB:fab_color pressed =@彩色/ colorprimary
            FAB:fab_size =迷你
            FAB:fab_icon =@绘制/ ic_add_white
            机器人:ID =@ + ID / fab_add/>    < / LinearLayout中>
< / LinearLayout中>
    <微调
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:layout_weight =10
        机器人:ID =@ + ID / sp_nomre_itm        机器人:项=@阵列/度/>
<的LinearLayout
    机器人:layout_width =0dp
    机器人:layout_height =FILL_PARENT
    机器人:layout_weight =10
    机器人:比重=中心
    >
    <! - LinearLayout中baraye INE科nameshod晶圆厂RO重量behosh爸爸 - >
    < com.getbase.floatingactionbutton.FloatingActionButton
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        晶圆厂:fab_plusIconColor =#ff56ff83
        FAB:fab_colorNormal =@彩色/ d_green
        FAB:fab_color pressed =@彩色/ d_orange
        晶圆厂:fab_size =正常
        FAB:fab_icon =@绘制/ ic_done_white
        机器人:ID =@ + ID / fab_hazr/>< / LinearLayout中>
< esfandune.ir.elmikarbordiardakan.other.CustomTxtView
    机器人:layout_weight =5
    机器人:layout_width =0dp
    机器人:layout_height =FILL_PARENT
    机器人:textAppearance =机器人:ATTR / textAppearanceLarge
    机器人:文字=100
    机器人:重力=右| center_vertical
    机器人:ID =@ + ID / txt_ghybtNumber_itm/>< esfandune.ir.elmikarbordiardakan.other.CustomTxtView
        机器人:layout_weight =30
        机器人:layout_width =0dp
        机器人:layout_height =FILL_PARENT
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:文字=عباسعلیملاحسینیاردکانی
        机器人:重力=右| center_vertical
        机器人:ID =@ + ID / txt_title_itm
    机器人:layout_marginRight =10dp
    /><查看
    机器人:layout_width =0dp
    机器人:layout_height =FILL_PARENT
    机器人:layout_weight =10
    类=de.hdodenhof.circleimageview.CircleImageView
    机器人:ID =@ + ID /视图
    机器人:SRC =@绘制/ mmrdf
   />
< / LinearLayout中>


解决方案

在您的适配器你在哪里膨胀的 onCreateViewHolder 的项目,是<$的第二个参数C $ C>膨胀通话

如果因此将其更改为这是在 onCreateViewHolder 函数签名的第一个参数。

 查看rootView = LayoutInflator.from(上下文).inflate(R.layout.itemLayout,父母,假);

如果你需要的第二个参数是然后当你在充气获取视图参考,请执行以下操作

 查看rootView = LayoutInflator.from(上下文).inflate(R.layout.itemLayout,空,假);
RecyclerView.LayoutParams LP =新RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.setLayoutParams(LP);
RecyclerViewHolder持有人=新RecyclerViewHolder(rootView);
回到持有人;

My RecyclerView and item has match_parent width but the result is :

    <view
    class="android.support.v7.widget.RecyclerView"
    android:layout_width="match_parent"

and items:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_itm"
android:orientation="horizontal"
android:layout_width="match_parent"

full:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_itm"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:gravity="right"
>


<Button
    android:layout_width="0dp"
    android:layout_weight="15"
    android:layout_height="fill_parent"
    android:text="ملاحظات"
    android:id="@+id/button" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="20"
    android:gravity="center"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            fab:fab_plusIconColor="#ff56ff83"
            fab:fab_colorNormal="@color/d_red"
            fab:fab_colorPressed="#ff5c86ff"
            fab:fab_size="mini"
            fab:fab_icon="@drawable/ic_remove_white"
            android:id="@+id/fab_rmv" />
        <esfandune.ir.elmikarbordiardakan.other.CustomTxtView
            android:layout_weight="25"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="0"
            android:gravity="right|center_vertical"
            android:id="@+id/txt_takhir_itm" />
        <com.getbase.floatingactionbutton.FloatingActionButton
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            fab:fab_plusIconColor="@color/colorprimarylight"
            fab:fab_colorNormal="@color/colorprimarydark"
            fab:fab_colorPressed="@color/colorprimary"
            fab:fab_size="mini"
            fab:fab_icon="@drawable/ic_add_white"
            android:id="@+id/fab_add" />

    </LinearLayout>
</LinearLayout>
    <Spinner
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="10"
        android:id="@+id/sp_nomre_itm"

        android:entries="@array/degrees"/>


<LinearLayout
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="10"
    android:gravity="center"
    >
    <!--LinearLayout baraye ine ke nameshod fab ro weight behosh dad-->
    <com.getbase.floatingactionbutton.FloatingActionButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        fab:fab_plusIconColor="#ff56ff83"
        fab:fab_colorNormal="@color/d_green"
        fab:fab_colorPressed="@color/d_orange"
        fab:fab_size="normal"
        fab:fab_icon="@drawable/ic_done_white"
        android:id="@+id/fab_hazr" />



</LinearLayout>
<esfandune.ir.elmikarbordiardakan.other.CustomTxtView
    android:layout_weight="5"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="100"
    android:gravity="right|center_vertical"
    android:id="@+id/txt_ghybtNumber_itm" />

<esfandune.ir.elmikarbordiardakan.other.CustomTxtView
        android:layout_weight="30"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="عباسعلی ملاحسینی اردکانی"
        android:gravity="right|center_vertical"
        android:id="@+id/txt_title_itm"
    android:layout_marginRight="10dp"
    />

<view
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="10"
    class="de.hdodenhof.circleimageview.CircleImageView"
    android:id="@+id/view"
    android:src="@drawable/mmrdf"
   />
</LinearLayout>

解决方案

In your adapter where you are inflating the item in onCreateViewHolder, is the second parameter of the inflate call null?.

If so change it to parent which is the first parameter in the onCreateViewHolder function signature.

View rootView = LayoutInflator.from(context).inflate(R.layout.itemLayout, parent, false);

If you need the second parameter to be null then when you get the view reference on inflating, do the following

View rootView = LayoutInflator.from(context).inflate(R.layout.itemLayout, null, false);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.setLayoutParams(lp);
RecyclerViewHolder holder = new RecyclerViewHolder(rootView);
return holder;

这篇关于match_parent宽度不RecyclerView工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆