Skip to content Skip to sidebar Skip to footer

Textview.setmaxlines Not Working?

In my app I have a screen where I display some text and then a photo. The text is variable in length (sometimes none at all, sometimes a lot), so I wanted to have it set up so the

Solution 1:

Try removing the call to setSingleLine. And use setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE). It'd also put this call before the setMaxLines and setLines call to be sure.

Note: setLines overrides the settings of setMaxLines and setMinLines.

The TextView has many issues surrounding the various calls to how it should display multiple, ellipses, etc.

Solution 2:

The setSingleLine(false) seemes to reset the setMaxLines command. Try to move the setSingleLine command before the setText. That worked for me.

Solution 3:

The below code is working fine for me

   txt = (TextView)findViewById(R.id.textview);
   txt.setMaxLines(5);
   txt.setMovementMethod(newScrollingMovementMethod());

   txt.setScrollContainer(true);
   txt.setText("Example Text");
   txt.setTextColor(Color.WHITE);
   txt.setScrollbarFadingEnabled(true);

in xml inside textview

   android:scrollbars="vertical"

Post a Comment for "Textview.setmaxlines Not Working?"