[英]Multiline TextView with line breaks wrapping
I'm trying to create a custom infocontents template for a Google Maps pin and I'm running in to some weird behavior when it comes to wrapping a multiline TextView
which contains text with multiple line breaks when using the following code:我正在尝试为 Google 地图 pin 创建自定义信息内容模板,并且在使用以下代码时,在包装包含带有多个换行符的文本的多行
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:结果:
As shown in the image the text after the first wrapped line is missing.如图所示,第一个换行后的文本丢失。 If there are no wrapped lines, or the last line is a wrapped line, then all lines are perfectly shown (see image below).
如果没有回绕线,或者最后一行是回绕线,则所有线都完美显示(见下图)。 Does anyone know how to get this to work properly?
有谁知道如何让它正常工作?
Muhammad Babar's suggestion fixes the issue. Muhammad Babar 的建议解决了这个问题。 I added a RelativeLayout as the parent of the LinearLayout and now all text is properly shown (see below for working code).
我添加了一个 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.