简体   繁体   English

在TextView中包装多行文字-Android

[英]Wrapping of multiline text in TextView - Android

I have a multiline TextView with a layout_width="wrap_content" property. 我有一个具有layout_width =“ wrap_content”属性的多行TextView。 The problem is when the TextView actually becomes multiline then this property just doesn't work. 问题是当TextView实际上变成多行时,此属性就不起作用了。 How can I fix this behavior? 如何解决此问题?

Here is illustration: 这是插图:

在此处输入图片说明

XML: 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"
                />

It seems that you are using parent view (ViewGroup) where you have defined background for your box. 似乎您正在使用父视图(ViewGroup),其中已为框定义背景。 You just need to define background for you TextView instead of ViewGroup. 您只需要为TextView而不是ViewGroup定义背景。 So, do not use background in your ViewGroup, try to use it in the textview. 因此,请勿在ViewGroup中使用背景,而应在textview中使用它。 For example: 例如:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM