Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView with too long Strings

I have this layout

<ScrollView>
    <TextView android:id="@+id/textView" />
</ScrollView>

When I try to set a too long text, this Textview doesn't show that.

//OnCreate
//...
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("..."); //Here is a text with more than 2500
                        //chars and at least have 10 \n char
                        //(it means has at least 10 paragraph)

How can do I show that text?

Edit One :

Even I set a background to that TextView and the TextView does'nt show that background

like image 535
Hossain Khademian Avatar asked Feb 07 '14 10:02

Hossain Khademian


3 Answers

you can set

android:maxLines="1"
android:ellipsize="end"

to your textview, so the text which long than your textview will be hide.

like image 133
Qilin Lou Avatar answered Oct 21 '22 22:10

Qilin Lou


Because android:singleLine="true" attribute has been deprecated, set the following attributes to your TextView:

android:ellipsize="end"
android:maxLines="1"

The TextView will then show only the text that can fit to your TextView, followed by an ellipsis ...

like image 4
Audwin Oyong Avatar answered Oct 21 '22 22:10

Audwin Oyong


i dont know if this will help you but saw this on developer.android...

With Android 8.0 (API level 26) and higher, you can instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.

android:autoSizeTextType="uniform"

There are three ways you can set up the autosizing of TextView:

Default

Granularity

Preset Sizes

=================================================

readMore

like image 4
ynroot Avatar answered Oct 21 '22 21:10

ynroot