Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.
I have searched and tried the following:
android:scrollHorizontally="false",
android:inputType="textMultiLine",
android:singleLine="false"
But none work..
Can anyone suggest how can i do it.. i am relatively new to android platform..
For the case where the
TextView
is inside aTableLayout
, the solution is to setandroid:shrinkColumns="1"
on theTableLayout
. (Replace1
with the column number the TextView you want to wrap is in. (0-indexed))AFAICT, no other attributes are needed on the
TextView
.For other cases, see the other answers here.
FWIW, I had initially gotten it to sort of work with
but that resulted in some extra empty space at the bottom of the Dialog it was all in.
Try @Guykun's approach and make sure that parents width is not set to wrap content. This is the thing that I was missing.
For me this issue only occurred on Android < 4.0
The combination of parameters I used were:
The maxLines count seemed to be the random final piece that made my TextView wrap.
OK guys the truth is somewhere in the middle cause you have to see the issue from the parent's view and child's. The solution below works ONLY when spinner mode =
dialog
regardless of Android version (no problem there.. tested it in VD and DesireS with Android =>2.2) :.Set you spinner's(the parent) mode like :
Set the textview's(child custom view) properties to :
I hope this works for you also.
You need to add your TextView in a ScrollView with something like this :
Strange enough - I created my TextView in Code and it wrapped - despite me not setting anything except standard stuff - but see for yourself:
As you can see from the params definition I am using a LinearLayout. The class Label simply extends TextView - not doing anything there except setting the font size and the font color.
When running it in the emulator (API Level 9) it automatically wraps the text across 3 lines.