Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

enter image description here

but in my application i get text wrapping as follows in the figure: enter image description here

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.

like image 457
M.A.Murali Avatar asked Mar 27 '12 08:03

M.A.Murali


3 Answers

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"
like image 68
waqaslam Avatar answered Oct 21 '22 17:10

waqaslam


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" />
like image 33
blueware Avatar answered Oct 21 '22 18:10

blueware


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"

like image 29
tzg Avatar answered Oct 21 '22 18:10

tzg