在我的应用程序中,我具有长文本的文本视图。我需要像在android模拟器->联系人->电话(联系人中的拨号盘屏幕不足)中一样自动换行。
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9XdFZMeS5wbmcifQ==” alt =“在此处输入图像描述”>
但是在我的应用程序中,我得到如下图所示的自动换行符:
我已经尝试了几种不符合我要求的方法。我不需要文本视图右上角的“ ...”。代替的是,我想像第一个数字那样包装文本(android模拟器->联系人->电话)。怎么做?请帮我。预先感谢。
我认为将以下属性设置为TextView应该可以帮助您实现此行为:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:singleLine="false"
或者,您可以根据TextViews
使用支持库的the Android docs自动调整大小。
如何使用?
对于API 26及更高版本:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform" />
要支持早期版本的Android,您可以使用:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" />
如果您有增加/减小TextView
大小的选项,则可以执行:
对于API 26及更高版本:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp" />
对于早期版本:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="12sp"
app:autoSizeMaxTextSize="100sp"
app:autoSizeStepGranularity="2sp" />
Android Studio 3.5
您需要做的就是在textView内的constraintlayout中设置一个End约束:
app:layout_constraintEnd_toEndOf="parent"