在TextView中包装多行文本 - Android

时间:2012-06-16 18:06:24

标签: android

我有一个带有layout_width =“wrap_content”属性的多行TextView。问题是什么时候 TextView实际上变成多行,然后这个属性不起作用。我该如何解决这个问题?

以下是插图:

enter image description here

XML:

    <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textColor="#000000"
                  android:focusable="false"
                  android:textSize="16.5dip"
                  android:padding="2dip"
                  android:lineSpacingMultiplier="1.1"
                />

1 个答案:

答案 0 :(得分:-1)

您似乎正在使用父视图(ViewGroup),您已为其定义了框的背景。您只需要为TextView而不是ViewGroup定义背景。 因此,不要在ViewGroup中使用背景,尝试在textview中使用它。例如:

<FrameLayout android:layout_width="fill_parent"
             android:layout_height="wrap_content">

<TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#000000"
              android:focusable="false"
              android:textSize="16.5dip"
              android:padding="2dip"
              android:lineSpacingMultiplier="1.1"
              android:background="@drawable/background_box"
            />

</FrameLayout>