android - 如何在Android的textview中换行

标签 android textview word-wrap

有谁知道如何在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 宽度允许左/右约束来确定小部件的宽度。

设置左/右约束设置您的小部件的实际宽度,您的文本将在该宽度内换行。

Constraint Layout docs

关于android - 如何在Android的textview中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4851659/

相关文章:

android - 如何在不取消滚动的情况下检测 TextView 上的 throw ?

CSS 文本总是跨同一行

android - 在 Android 中排序 Arraylist

java - Android 应用程序可以在模拟器上正常运行,但在 Android 手机上运行时速度非常慢

android - com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'

html - ASP :TextBox with TextMode ="MultiLine" Wrap ="True" will not wrap

html - 为什么这些 flex 元素没有包裹起来?

java - 游戏编程: passing main class to every object

android - 如何检测Textview中的网站链接并使其可点击

android - 如何使用 Android TagHandler 读取自定义 html 标签属性