简体   繁体   中英

android textview not wrapping correctly

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>
 <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"

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());

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM