主要问题描述:启动一个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>