2

Я пытаюсь создать пользовательский шаблон инфо-контента для значка Google Maps, и я столкнулся с каким-то странным поведением, когда дело доходит до обертывания многострочного TextView, который содержит текст с несколькими разрывами строк, когда используя следующий код:Многострочный TextView с обрывом обрыва строк

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="4dp" 
    android:paddingTop="4dp" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/OfficeImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|center_horizontal" 
     android:scaleType="centerInside" 
     android:adjustViewBounds="true" 
     android:maxWidth="175dp"/> 
    <TextView 
     android:layout_marginTop="10dp" 
     android:id="@+id/InfoWindowTitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Sunshine Coast" 
     android:textColor="@android:color/black" 
     android:textStyle="bold"/> 
    <TextView 
     android:id="@+id/InfoWindowSubtitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:singleLine="false" 
     android:textSize="10dp" 
     android:text="Level 3, 2 Emporio Place\n2 Maroochy Blvd, Maroochydore QLD 4558\nPo Box 5800, Maroochydore BC QLD 4558" 
     android:maxLines="10" 
     android:textColor="@android:color/black"/> 
</LinearLayout> 

Результат:

Result

Как показано на изображении текст после первой завернутые линии отсутствует. Если нет завернутых линий, или последняя строка - завернутая строка, то все строки прекрасно отображаются (см. Изображение ниже). Кто-нибудь знает, как заставить это работать правильно?

Expected Result

+1

Попробуйте использовать RelativeLayout в качестве родителя. –

ответ

1

Muhammad Babar's предложение устраняет проблему. Я добавил RelativeLayout в качестве родителя LinearLayout, и теперь весь текст отображается правильно (см. Ниже рабочий код).

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="4dp" 
    android:paddingTop="4dp" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/OfficeImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|center_horizontal" 
     android:scaleType="centerInside" 
     android:adjustViewBounds="true" 
     android:maxWidth="175dp"/> 
    <TextView 
      android:layout_marginTop="10dp" 
      android:id="@+id/InfoWindowTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Sunshine Coast" 
      android:textColor="@android:color/black" 
      android:textStyle="bold"/> 
    <TextView 
     android:id="@+id/InfoWindowSubtitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:text="Level 3, 2 Emporio Place\n2 Maroochy Blvd, Maroochydore QLD 4558\nPo Box 5800, Maroochydore BC QLD 4558" 
     android:maxLines="10" 
     android:textColor="@android:color/black"/> 
    </LinearLayout> 
</RelativeLayout>