Maximum line length on Android TextView

I'm putting a formatted single line text (no \n's) to a noneditable TextView. In the navigation of the program, the text can be changed. On some text, the TextView shrinks to 0x0 pixel and I can see nothing! I added some menus to truncate the text 10 characters each time and I found that if the number of characters are larger than 4470, the TextView shrinks.

Splitting the text into several lines by putting \n in between solves the problem, but that's not my intention.

Could you help me find if this is documented, or is there anything that can be set to remove this limitation?

Asked by: Lily779 | Posted: 24-01-2022

Answer 1

I did some testing. It seems this value is not fixed. It moved up and down each time. But there are some limits:

  • TextView.maxLines is Integer.MAX_VALUE by default (2147483647)
  • TextView.maxEms is Integer.MAX_VALUE by default
  • Java Strings in general are Integer.MAX_VALUE or half the maximum heap size

On my first test it worked up to 179 899 characters in a single line. By adding android:maxLength="10000000" to the xml I got up to 184 200. But that number worked just once. With a \n line break after every character I got up to about 750 000.

It's interesting to note that the textView never shrunk like it did back then. The app crashed instead:

Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 0 free bytes and 0B until OOM, target footprint 536870912, growth limit 536870912" (VmSize 2143664 kB, recursive case)

I used a Pixel 3 API 29 emulator with 1536 mb ram, 256mb heap and the following code:

StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i<750000; i++) {

I didn't find anything in the documentation.

The bottom line is there is no practical maximum and phones have a lot more memory today...

Answered by: Miranda461 | Posted: 25-02-2022

Similar questions

Maximum line limits for Textview in android?

Maximum line limits for Textview in android ? android:maxLines="?"

java - How can I get the maximum length of a textView in Android?

Hello I created a textview in the main layout, with a certain value for android:maxLength. Now I'd like to get that value back into an int variable; I know how to refer to the textView in Java, but there are no direct methods in the TextView Object to get its maximium length. Is there any way to obtain this value?

android - maximum TextView width in layout file

i have a small layout file for the parentView of the ExpandableListView. If the TextView text is too long it overlays some other views of the layout. Here is an image: enter link description here and here is the layout file: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="

Android textView bug? Maximum text size in sp

Is there any maximum text size for TextView in Android? My application has to display some text in around 290sp. However, I found that some of the devices cannot display it and a whole blank page is TextView is shown. In Samsung Galaxy Note 5 (API 23), it works find. In Google Nexus 5 (API 19), the maximum text size is 239sp. In Samsung Galaxy S7 (API 23), the maximum text size is 179sp. Below is ...

java - How to limit maximum length of Textview in Android, i want to set 10 lines and 100 words

This question already has answers here:

android - Can I hook when user copy or paste on TextView?

When user copy or paste on TextView, Is there anyone explains me what happen on TextView. If some methods called while user click 'Copy' or 'Paste' in menus, I'd like to hook them and replace them with my own one. Here is what I want to do. 1. user copy or paste some string to my TextView. 2. some string copied and paste on my Textview. 3. Before some string is added on Textview, I want to check or change string.

android - How to bind more then one column to a textview

I am curious if there is a way to bind more then one db column to a resource. I need to bind more information to then just the difficulty column. But I'm unsure how to go about this? I'm currently subclassing SimpleCursorAdapter. Should I subclass another adapter? If so How to do I go about it? Cursor activityHikes = mDbAdapter.fetchAllHikes(false); startManagingCursor(activityHikes)...

Android TextView Text not getting wrapped

Can anyone tell me what's going wrong with the text? Text longer than one line doesn't wrap to the next line but goes beyond the screen. Following is the code: &lt;LinearLayout xmlns:android="" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="4dip"&gt; &lt;LinearL...

Ordered lists inside an Android TextView

I want to display an ordered list inside a TextView, for example: 1) item 1 2) item 2 Using the following layout: &lt;TextView android:text="&lt;ol&gt;&lt;li&gt;item 1\n&lt;/li&gt;&lt;li&gt;item 2\n&lt;/li&gt;&lt;/ol&gt; /&gt; I get: item 1 item 2 How can I change the bullets to numbers? Thanks.

android - How to display HTML in TextView?

I have simple HTML: &lt;h2&gt;Title&lt;/h2&gt;&lt;br&gt; &lt;p&gt;description here&lt;/p&gt; I want to display HTML styled text it in TextView. How to do this?

how to change text in Android TextView

I tried to do this @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t=new TextView(this); t=(TextView)findViewById(; t.setText("Step One: blast egg"); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printSta...

android - Color of the text in TextView changes color

In android, when I press on a TextView, the text changes color (from white to grey). Can you please tell me how can I disable that functionality? Thank you.

How can you display upside down text with a textview in Android?

How can you display upside down text with a textview in Android? In my case I have a 2 player game, where they play across from each other. I want to display test to the second player oriented to them. This was the solution I implemented after AaronMs advice The class that does the overriding, package; import android.content.Context; import andr...

textview - How to know all id's that i have in the file main.xml in android?

i'm new at Android world, and i have a doubt, is there any method that give me the name of the id's i create in main.xml? For example i have this: main.xml &lt;TextView android:id="@+id/text1" android:layout_width="70px" android:layout_height="70px" android:text="Google" /&gt; &lt;TextView android:id="@+id/text2" android:layout_width="70px" android:layout_h...

How do I add a newline to a TextView in Android?

When I define a TextView in xml, how do I add a new line to it? \n seems not to work. &lt;TextView android:id=&quot;@+id/txtTitlevalue&quot; android:text=&quot;Line1 -\nLine2&quot; android:layout_width=&quot;54dip&quot; android:layout_height=&quot;fill_parent&quot; android:textSize=&quot;11px&quot; /&gt;

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android