Мои требования: создать "входящий пузырь" с шириной по содержанию и максимальной шириной 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>
Иногда я получаю следующий результат:
Но я ожидаю следующий результат (это ложное поощрение скриншота из предварительного просмотра Android Studio):
Как я могу предотвратить разбиение слова restaraunt
на буквы?
UPDATE
Хотя я использую minSdk = 15, я попытался использовать breakStrategy
, и я не получил ожидаемого результата.
android:breakStrategy="simple"
:
android:breakStrategy="balanced"
:
Я нашел связанный с этим вопрос: Принудительное следующее слово к новой строке, если слово слишком длинное для текстового поля, но я не понял, как я могу получить максимальная доступная ширина для TextView с layout_width="wrap_content
?
Было бы здорово, если бы я мог переопределить TextView.setText
и поместить там разрывы строк там, где это необходимо.