Лучший способ - использовать Recycler View и добавить разделитель между всеми элементами: посмотрите на это Как добавить разделители и пробелы между элементами в RecyclerView?
И использовать макет этого элемента:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/message_content_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/message_end_green_view"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:padding="8dp">
<TextView
android:id="@+id/tv_received_message_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Received message:"
android:textColor="@color/green"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="4dp"/>
<TextView
android:id="@+id/tv_received_message_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv_received_message_key"
app:layout_constraintTop_toTopOf="parent"
tools:text="Message" />
<View
android:id="@+id/tv_message_divider"
android:layout_width="0dp"
android:layout_height="2dp"
android:background="@color/grey_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_received_message_key"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/tv_reply_message_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Repley message:"
android:layout_marginTop="8dp"
android:textColor="#4caf50"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_message_divider"
android:layout_marginStart="4dp"/>
<TextView
android:id="@+id/tv_reply_message_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv_reply_message_key"
app:layout_constraintTop_toTopOf="@id/tv_reply_message_key"
app:layout_constraintBottom_toBottomOf="@id/tv_reply_message_key"
tools:text="Message" />
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:id="@+id/message_end_green_view"
android:layout_width="8dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@drawable/shape_rectangle_green"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
, в котором shape_rectangle_green это рисование:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#4caf50" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="0dp"
android:topRightRadius="8dp" />
</shape>
Я позволяю вам изменять поля, отступы и цвета.