我的要求:创建“传入气泡”,其宽度按内容排列,最大宽度为 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:
But I expect the following result (it's falsely encouraging screenshot from Android Studio preview):
如何防止破词restaraunt
通过字母?
UPDATE
Although I use minSdk=15 I tried to use breakStrategy
and I haven't get expected result.
android:breakStrategy="simple"
:
android:breakStrategy="balanced"
:
我发现了一个相关问题:如果单词对于文本视图来说太长,则强制下一个单词换行 https://stackoverflow.com/questions/25636827/force-next-word-to-a-new-line-if-the-word-is-too-long-for-the-textview,但我不明白如何获得 TextView 的最大可用宽度layout_width="wrap_content
?
如果我可以覆盖的话那就太好了TextView.setText
并根据需要在此处放置换行符。
天哪,有
在我的绳子里!
value.replaceAll("\\s", " ");
谢谢你们!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)