有谁知道如何在Android平台的TextView中换行。即如果 textview 中的文本超过屏幕长度,则应显示在第二行。
我已经搜索并尝试了以下内容:
android:scrollHorizontally="false",
android:inputType="textMultiLine",
android:singleLine="false"
但没有任何工作..
谁能建议我该怎么做。
最佳答案
约束布局
<TextView
android:id="@+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@id/textview_above"
app:layout_constraintRight_toLeftOf="@id/button_to_right"/>
- 确保您的布局宽度为零
- 定义了左/右约束
- wrap_content 的布局高度允许向上/向下扩展。
- 设置
android:maxLines="2"
以防止垂直扩展(2 只是一个例子) - 椭圆是概率。最大行数的好主意
android:ellipsize="end"
0dp 宽度允许左/右约束来确定小部件的宽度。
设置左/右约束设置您的小部件的实际宽度,您的文本将在该宽度内换行。
关于android - 如何在Android的textview中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4851659/