Android 我能';t设置文本视图布局高度以包装内容

Android 我能';t设置文本视图布局高度以包装内容,android,layout,textview,height,Android,Layout,Textview,Height,这是我的代码: 在本例中,只有2行文本可见,但行数多于2行。如何设置此TextView的高度以包装内容而不是使其溢出?尝试将其添加到您的TextView: android:singleLine="false" android:padding="10dp" 您需要将其添加到文本视图中 android:inputType="textMultiLine" android:lines="3" 如果您确实需要一个多行文本框来定义文本用途 android:singleLine="false"

这是我的代码:



在本例中,只有2行文本可见,但行数多于2行。如何设置此TextView的高度以包装内容而不是使其溢出?

尝试将其添加到您的TextView:

android:singleLine="false"
android:padding="10dp"

您需要将其添加到文本视图中

android:inputType="textMultiLine"
android:lines="3"


如果您确实需要一个多行文本框来定义文本用途

android:singleLine="false"
但它不适合长文本。因为有时候它会溢出你的布局。因此,最好使用可滚动的文本视图

android:maxLines = "4"
android:scrollbars = "vertical"

将填充添加到textview:

android:singleLine="false"
android:padding="10dp"
例如:

<TextView
                android:layout_width="0dp"
                android:layout_weight=".50"
                android:layout_height="wrap_content"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting"
                android:layout_column="1"
                android:padding="10dp"/>

使用多行文本视图