【发布时间】:2020-12-27 14:30:55
【问题描述】:
我必须实现一个聊天机器人,但我不知道如何为消息调整文本视图的大小。
我希望气球完全适合文本,右边没有白色空白,不使用maxWidth。
我的代码是
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/bot_icon"
android:layout_width="50dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:src="@drawable/ic_botchat"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/bot_icon"
app:layout_constraintTop_toBottomOf="@id/bot_icon">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/textMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="@drawable/bot_message"
android:elevation="3dp"
android:fontFamily="@font/roboto"
android:paddingStart="16dp"
android:paddingTop="10dp"
android:paddingEnd="16dp"
android:paddingBottom="10dp"
android:textColor="@color/visia"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我尝试用wrap_content修改AppCompatTextView中的android:layout_width,但是文本显示在一行中,超出了屏幕。
【问题讨论】:
-
您需要以这种方式设计您的 .9.png 图像(背景气泡)。
标签: android xml kotlin textview chat