XRecyclerView的item条目宽度滚动变化无法填充满的问题 (或RecyclerView)

主要问题描述:启动一个dialogfragment的时候,item条目无法match parent 向下滑动条目,新加载出来的条目可以match parent;造成item的宽度随着界面活动变换;


需要设置调整2个设置:
//View view = View.inflate(parent.getContext(), R.layout.item_person, null);  这种设置修改为:
View view=LayoutInflater.from(context).inflate(R.layout.item_person,parent,false);把parent参数传入

XRecyclerView的使用代码

<com.jcodecraeer.xrecyclerview.XRecyclerView
    android:id="@+id/RV"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@color/light_gray"
    android:paddingLeft="@dimen/margin_10"
    android:paddingRight="@dimen/margin_10" />

第二步 :item_person的最外层节点设置 android:layout_width="300dp" 固定宽度,才能解决此问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="@dimen/margin_5">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@color/white"
        app:cardCornerRadius="8dp">

        <LinearLayout
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="@dimen/margin_10"
            android:paddingLeft="@dimen/margin_15"
            android:paddingRight="@dimen/margin_15"
            android:paddingTop="@dimen/margin_5">

            <TextView
                android:id="@+id/name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/ic_head_blue"
                android:drawablePadding="8dp"
                android:gravity="center_vertical"
                android:text="姓名"
                android:textColor="@color/light_blue"
                android:textSize="@dimen/size_content" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/deptname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="工作单位"
                    android:gravity="right"
                    android:textColor="@color/primary_text"
                    android:textSize="@dimen/size_content" />
            </RelativeLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值