我正在尝试构建聊天布局。一切正常。当用户相互匹配时,他们可以写消息并且消息出现在聊天屏幕中。但是,我的聊天气泡之间存在巨大差距。
我阅读了官方 Android Chat Bubble 文档,浏览了 YouTube 视频和堆栈溢出。我真的不明白我哪里错了。我的气泡是实时出现的,我可以在使用两个虚拟 android 设备进行测试时读取用户的聊天记录,但是聊天记录之间存在巨大的差距,并且彼此之间没有重叠。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent"
tools:context=".activities.ChatActivity">
<LinearLayout
android:id="@+id/navigationLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/navigation_height"
android:layout_margin="@dimen/chat_margin"
android:background="@color/shadow"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/topPhotoIV"
android:layout_width="@dimen/navigation_height"
android:layout_height="@dimen/navigation_height"
android:layout_marginRight="@dimen/chat_margin"
android:scaleType="centerInside"/>
<TextView
android:id="@+id/topNameTV"
android:layout_width="match_parent"
android:layout_height="@dimen/navigation_height"
android:gravity="center_vertical"
android:textSize="20sp"
android:paddingLeft="@dimen/chat_margin"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messagesRV"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/messageET"
app:layout_constraintTop_toBottomOf="@+id/navigationLayout" />
<Button
android:id="@+id/sendButton"
style="@style/sendButton"
android:layout_width="@dimen/send_width"
android:layout_height="@dimen/send_height"
android:layout_margin="@dimen/chat_margin"
android:onClick="onSend"
android:text="@string/send_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<EditText
android:id="@+id/messageET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxHeight="@dimen/send_height_max"
android:layout_margin="@dimen/chat_margin"
android:padding="@dimen/chat_margin"
android:gravity="center_vertical"
android:background="@drawable/chat_box_bg_rounded"
android:hint="@string/hint_message"
android:minHeight="@dimen/send_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sendButton"
app:layout_constraintStart_toStartOf="parent" />
我最终将回收站 View 更改为 wrap_content,它仍然存在差距。我想我在这里遗漏了什么?
所以我进入了 item_current_user_message.xml 和 item_other_user_message.xml 并将 match_parent 切换为 wrap_content 瞧,它起作用了。 :) 谢谢你!
最佳答案
这个问题是因为 match_parent
高度到聊天适配器的 layout
。确保适配器的布局的高度应为 wrap_content
。将高度设置为 wrap_content
将解决问题。
关于Android Studio kotlin 聊天屏幕布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59019424/