4

I have the following xml to display rows in a listView. I want the TextView with the id rowCreatedAt, to wrap around nicely but it never does and only shows 1 line. I tried most of the solutions in the other questions and added them in the code, but it still doesn't work. Can anyone tell me why...?

+I would like to avoid setting the exact size to the textview.

++ To put it differently, why does the rowCreatedAt textView doesn't wrap the text when width/height is set to fill_parent while other textViews wrap texts just fine?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_margin="5dp"
    android:layout_marginBottom="5dp" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/rowUserImage"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/twitter_icon" 
            android:layout_margin="5dp"/>

        <TextView
            android:id="@+id/rowCreatedAt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="10dp"
            android:textColor="#ff696969"
            android:ellipsize="none"
            android:singleLine="false"
            android:scrollHorizontally="false"
            android:layout_weight="1"
            android:maxLines="100"
            android:text="aaaaaaaaaaaaaaabbbbbbbbbbbbbb" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/rowUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="username"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/rowText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="status text" />
    </LinearLayout>

</LinearLayout>
amor0624
  • 45
  • 1
  • 1
  • 5
  • possible duplicate of [Android TextView Text not getting wrapped](http://stackoverflow.com/questions/2197744/android-textview-text-not-getting-wrapped) – mayo Sep 24 '15 at 03:25

4 Answers4

3
 <TextView
            android:id="@+id/rowCreatedAt"
             android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="10dp"
            android:textColor="#ff696969"
            android:ellipsize="none"
            android:singleLine="false"
            android:scrollHorizontally="false"
            android:layout_weight="1"
            android:maxLines="100"
            android:text="aaaaaaaaaaaaaaabbbbbbbbbbbbbb" />

Change android:layout_width="fill_parent" to android:layout_width="200dp"

Looking Forward
  • 3,579
  • 8
  • 45
  • 65
  • using 'wrap_content' makes the parent layout wider. What I want is to keep the width of the parent layout stays the same and so does the width of this textView: just need the text to wrap around to display all. – amor0624 Dec 10 '13 at 04:57
  • then fix the siz of textview such as android:layout_width="200dp" or as appropriate. – Looking Forward Dec 10 '13 at 05:02
  • Yeah then it works....I wanted to not set the exact size though. i guess it's the only way...? – amor0624 Dec 10 '13 at 05:07
  • thanks for the help Anil! I'll accept your answer if no one else can figure out a way to solve this without setting the exact size. – amor0624 Dec 10 '13 at 05:17
  • instead of width I suggest setting max width ( android:maxWidth="70dp" ) , though it's not a perfect solution – Shaz Aug 31 '15 at 11:11
  • it works, for my case. But why? Parent have 200dp width, so set match parent is 200dp. But it doesn't work. But when given value 200dp it works fine. – Jakub S. Feb 19 '18 at 09:51
1

Try like this :

            <TextView
            android:id="@+id/Lesson_Description"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:minLines="4"
            android:maxLines="6"
            android:gravity="right|center"
            android:background="@drawable/filed_shape_corner"
            android:inputType="textMultiLine" />

Then do something like in code :

mLessonDescription = (TextView) rootView
                .findViewById(R.id.Lesson_Description);


        mLessonDescription.setMovementMethod(new ScrollingMovementMethod());
Nagaraja
  • 581
  • 1
  • 4
  • 12
0

Try out be setting android:ems="10" it will make your edittext that much wide and wraps the other characters.

OR

You should use android:ellipsize="marquee". If you do not want to fix the height.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • How you want to wrap ? – GrIsHu Dec 10 '13 at 05:04
  • so the text in the textView appears on the screen without being cut. right now with the code I posted, only the first few characters appears on the screen.. – amor0624 Dec 10 '13 at 05:12
  • You need to fix the height of the textview. – GrIsHu Dec 10 '13 at 05:17
  • Try out by setting the height of the TextView `android:layout_height="50dp"` – GrIsHu Dec 10 '13 at 05:19
  • again, I would like to avoid setting the exact size. it makes the look ugly as the number of lines that needs to fit vary... would there be another way? – amor0624 Dec 10 '13 at 05:25
  • No you will have to wrap the text. You can not show the full text. If you want to show then either you have to wrap it or you can set the `ellipsize="end"` which will indicate that there is some more text also. Or you can set the `ems` as i have shown you in my answer. – GrIsHu Dec 10 '13 at 05:28
  • TextView is restricted to show the long text with adjustment of large text according to width. – GrIsHu Dec 10 '13 at 05:31
  • yes, I want to wrap the text. so my question is if there's a way to wrap it without setting height and width to a constant. Other textviews wraps around just fine with width/height set to 'fill_parent' but the one I questioned does not. – amor0624 Dec 10 '13 at 05:43
  • Other text will be adjusted as it does not have large text. If you want to display large text then you will have to wrap it or fix the height or width to show full text. – GrIsHu Dec 10 '13 at 05:54
0

Add the following style changes to fix the width problem. along with the initial changes

<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:singleLine">false</item>
<item name="android:maxLines">100</item>
<item name="android:width">0dp</item>
<item name="android:layout_weight">1</item>
dibble
  • 299
  • 3
  • 3