TextView用字母打破了我的话 [英] TextView breaks my word by letters
问题描述
我的要求:按内容宽度和最大宽度90%创建传入气泡。
My requirements: create "incoming bubble" with width by content and max width 90%.
我有这个标记:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
tools:background="@color/white_smoke">
<LinearLayout
android:id="@+id/flBubble"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@drawable/bubble_in"
android:layout_weight="0.9">
<ImageView
android:id="@+id/ivSay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/default_content_description"
android:padding="8dp"
android:src="@drawable/ic_play_circle_outline_black_24dp"
android:tint="@color/primary"/>
<TextView
android:id="@+id/tvValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:textColor="@color/black"
android:textSize="16sp"
tools:text="I would like to go to an Italian restaurant"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.1"/>
</LinearLayout>
有时我得到以下结果:
Sometimes I get the following result:
但我希望得到以下结果(它错误地鼓励Android Studio预览中的屏幕截图):
But I expect the following result (it's falsely encouraging screenshot from Android Studio preview):
如何通过信件防止破解餐厅
?
How can I prevent breaking word restaraunt
by letters?
虽然我使用minSdk = 15但我试图使用 breakStrategy
而我没有得到预期的结果。
android:breakStrategy =simple
:
Although I use minSdk=15 I tried to use breakStrategy
and I haven't get expected result.
android:breakStrategy="simple"
:
android:breakStrategy =balanced
:
我发现了一个相关的问题:如果单词对于textview来说太长,则强制下一个单词到新行,但我没有说明如何使用<$ c获得TextView的最大可用宽度$ c> layout_width =wrap_content ?
I found a related question: Force next word to a new line if the word is too long for the textview, but I didn't undestand how can I get maximum available width for TextView with layout_width="wrap_content
?
如果我可以覆盖 TextView.setText
并根据需要在那里放置换行符。
It would be great if I could override the TextView.setText
and place line breaks there if needed.
推荐答案
OMG,有& NBSP;
在我的字符串中!
OMG, there were
in my string!
value.replaceAll("\\s", " ");
谢谢大家!
这篇关于TextView用字母打破了我的话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!