how to do text wrapping for long text in text view on android

≡放荡痞女 提交于 2019-12-10 16:48:09

问题


In my application,i have text view with long text. i need text wrapping like in the android emulator->contact->phone (screen short of dialpad in contact).

but in my application i get text wrapping as follows in the figure:

i have tried several ways it does not meet my requirement. i do not need the "..." at right corner of the text view. instead of that, i want to wrap the text as in the first figure(android emulator->contact->phone). how to do that? please help me. Thanks in advance.


回答1:


I think setting the following properties to your TextView should help you to achieve this behavior:

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:singleLine="false"



回答2:


Alternatively, you can use support library's autosizing for TextViews as per the Android docs.

How to use?

For API 26 and later:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:autoSizeTextType="uniform" />

To support earlier version of Android you can use:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:autoSizeTextType="uniform" />

If you have an option that increases/decreases TextView size then you can do:

For API 26 and later:

<?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" />

For earlier versions:

<?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" />



回答3:


Android Studio 3.5

All you need to do is set an End constraint in a constraintlayout inside your textView:

app:layout_constraintEnd_toEndOf="parent"



来源:https://stackoverflow.com/questions/9885535/how-to-do-text-wrapping-for-long-text-in-text-view-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!