【发布时间】:2026-01-12 00:05:01
【问题描述】:
我有包含文本的 TextView。它有背景:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!\nEach line should be wrapped by background not whole text"
android:textColor="#000000"
android:textSize="24sp"
android:background="#FFFF00"
android:gravity="center_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="8dp"/>
现在,背景正在包裹整个文本。我希望它单独包装每一行。现在我得到了图像左侧显示的结果。我想达到右边的结果。
我会创建几个具有不同背景的 TextView,但 TextView 会显示动态文本,这使得该解决方案不太好。
我的问题:如何用背景包装 TextView 的每一行?
【问题讨论】: