问题描述:我在使用recyclerview时,显示Item显示不全:
1.前两个Item只显示了下半部分的Button,上面的布局不显示。
2.滑动后,原本显示的Item,再次滑出后,显示不全,最后所有的Item都只显示下面部分的Button。
<?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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/neworder_item_one_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_bg_up"
android:padding="10dp">
<ImageView
android:id="@+id/neworder_item_one_head_iv"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/item_man_head"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/neworder_item_one_username_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="left|center_vertical"
android:padding="2dp"
android:text="庞先生"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/neworder_item_one_company_tv"
app:layout_constraintLeft_toRightOf="@+id/neworder_item_one_head_iv"
app:layout_constraintRight_toLeftOf="@+id/neworder_item_one_time_tv"
app:layout_constraintTop_toTopOf="@+id/neworder_item_one_head_iv" />
<TextView
android:id="@+id/neworder_item_one_time_tv"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:drawableLeft="@drawable/timer"
android:drawablePadding="5dp"
android:gravity="right|center_vertical"
android:padding="2dp"
android:text="2018.01.18 12:45:00"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/neworder_item_one_username_tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/neworder_item_one_username_tv" />
<TextView
android:id="@+id/neworder_item_one_company_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="1"
android:padding="2dp"
android:text="@string/wifi_notice"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/neworder_item_one_head_iv"
app:layout_constraintLeft_toLeftOf="@+id/neworder_item_one_username_tv"
app:layout_constraintRight_toRightOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintTop_toBottomOf="@+id/neworder_item_one_head_iv">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_data_channel_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="数据渠道" />
<TextView
android:id="@+id/neworder_item_one_data_channel_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="网申二次营销" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_apply_time_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="申请时间" />
<TextView
android:id="@+id/neworder_item_one_apply_time_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="2018.01.08" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_order_mode_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="派单方式" />
<TextView
android:id="@+id/neworder_item_one_order_mode_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="人工导入" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="@+id/neworder_item_one_down"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_bg_down"
android:layout_below="@+id/neworder_item_one_up"
android:orientation="horizontal">
<Button
android:id="@+id/neworder_item_one_handle_btn"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/blue_transparent_rectangle"
android:text="处理"
android:textColor="@color/color_tab_indicator" />
<Button
android:id="@+id/neworder_item_one_return_btn"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/gray_transparent_rectangle"
android:text="退回"
android:textColor="@color/colorListDivider" />
</LinearLayout>
</LinearLayout>
运行效果:
修改布局后就可以显示了:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/neworder_item_one_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_bg_up"
android:padding="10dp">
<ImageView
android:id="@+id/neworder_item_one_head_iv"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/item_man_head"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/neworder_item_one_username_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="left|center_vertical"
android:padding="2dp"
android:text="庞先生"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/neworder_item_one_company_tv"
app:layout_constraintLeft_toRightOf="@+id/neworder_item_one_head_iv"
app:layout_constraintRight_toLeftOf="@+id/neworder_item_one_time_tv"
app:layout_constraintTop_toTopOf="@+id/neworder_item_one_head_iv" />
<TextView
android:id="@+id/neworder_item_one_time_tv"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:drawableLeft="@drawable/timer"
android:drawablePadding="5dp"
android:gravity="right|center_vertical"
android:padding="2dp"
android:text="2018.01.18 12:45:00"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@+id/neworder_item_one_username_tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/neworder_item_one_username_tv" />
<TextView
android:id="@+id/neworder_item_one_company_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="1"
android:padding="2dp"
android:text="@string/wifi_notice"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/neworder_item_one_head_iv"
app:layout_constraintLeft_toLeftOf="@+id/neworder_item_one_username_tv"
app:layout_constraintRight_toRightOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintTop_toBottomOf="@+id/neworder_item_one_head_iv">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_data_channel_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="数据渠道" />
<TextView
android:id="@+id/neworder_item_one_data_channel_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="网申二次营销" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_apply_time_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="申请时间" />
<TextView
android:id="@+id/neworder_item_one_apply_time_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="2018.01.08" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/neworder_item_one_order_mode_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="派单方式" />
<TextView
android:id="@+id/neworder_item_one_order_mode_value_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="人工导入" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:id="@+id/neworder_item_one_down"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_bg_down"
android:layout_below="@+id/neworder_item_one_up"
android:orientation="horizontal">
<Button
android:id="@+id/neworder_item_one_handle_btn"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/blue_transparent_rectangle"
android:text="处理"
android:textColor="@color/color_tab_indicator" />
<Button
android:id="@+id/neworder_item_one_return_btn"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/gray_transparent_rectangle"
android:text="退回"
android:textColor="@color/colorListDivider" />
</LinearLayout>
</RelativeLayout>