当我滚动我的recyclerView时,项目会像这样移动到外部:

这是我的xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_chat_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:menu="@menu/menu_chat_details"
app:title="toolbarChatDetails">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/button_back_chat_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/ic_baseline_arrow_back_ios_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image_user_chat_details"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="12dp"
android:src="@drawable/avatar"
app:civ_border_color="#515050"
app:civ_border_overlay="true"
app:civ_border_width="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_back_chat_details"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/username_chat_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="China Girl"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/image_user_chat_details"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/toolbar_chat_details"
android:background="#525252"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rcv_chat_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/layout_message"
android:layout_below="@id/toolbar_chat_details" />
<View
android:id="@+id/view_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@id/layout_message"
android:background="#AAAAAA"/>
<RelativeLayout
android:padding="8dp"
android:id="@+id/layout_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_toStartOf="@id/button_send_message_chat_details"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:scaleType="centerCrop"
android:id="@+id/button_send_image_chat_details"
android:layout_width="36dp"
android:visibility="visible"
android:layout_height="36dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_picture" />
<EditText
android:id="@+id/edt_send_message"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerInParent="true"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_toEndOf="@+id/button_send_image_chat_details"
android:background="@drawable/border_edt_chat_details"
android:backgroundTint="#F2F0F0"
android:hint="Type..."
android:paddingStart="8dp"
android:textColor="@color/black"
android:textSize="18sp" />
</RelativeLayout>
<ImageButton
android:layout_alignParentEnd="true"
android:scaleType="centerCrop"
android:id="@+id/button_send_message_chat_details"
android:layout_width="36dp"
android:visibility="invisible"
android:layout_height="36dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_send" />
</RelativeLayout>我没有办法解决这个问题,请帮帮我!
你要像没有人看一样跳舞,像永远不会受伤那样去爱,像没有人在听一样唱歌,像地球上的天堂一样生活。-威廉·W·普基( William W. Purkey )
祝大家今天愉快!
发布于 2021-08-22 10:52:42
将android:layout_height设置为RecyclerView的0dp
发布于 2021-08-22 10:53:00
请注意,您正在使用RelativeLayout作为父级。你现在有两个选择:
1.用垂直方向的LinearLayout代替RelativeLayout
2.在marginTop和marginBottom上使用RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:layout_marginTop="?actionBarSize"
android:layout_marginBottom="?actionBarSize"
android:id="@+id/rcv_chat_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/layout_message"
android:layout_below="@id/toolbar_chat_details" />https://stackoverflow.com/questions/68880576
复制相似问题