How to wrap long text as text on Android

In my application, I have a long text text view. I need a text wrap like in android phone-> contact-> (screen that no dialpad contact is wearing).

enter image description here

but in my application I get text wrapping like this in the picture: enter image description here

I tried several ways to make it not meet my requirement. I don't need the "..." in the right corner of the text view. instead, I want to wrap the text like in the first picture (Android emulator-> contact-> phone). how to do it? please, help. Thanks in advance.

+4


source to share


2 answers


I think the following properties need to be set to create this TextView property:



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

      

+7


source


Alternatively, you can use the library's auto-resize support for TextViews

as per Android documentation .

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 an earlier Android version, 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 the size TextView

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

      

0


source







All Articles