Faisal khan Faisal khan - 1 year ago 39
Android Question

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:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dip">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dip">
<TextView
android:id="@+id/reviewItemEntityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="event/venue"
android:textColor="@color/maroon"
android:singleLine="true"
android:ellipsize="end"
android:textSize="14sp"
android:textStyle="bold"
android:layout_weight="1" />

<ImageView
android:id="@+id/reviewItemStarRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:src="@drawable/title_1_star" />
</LinearLayout>

<TextView
android:id="@+id/reviewItemDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Description comes here"
android:textSize="12sp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

Answer Source

I fixed it myself, the key is android:width="0dip"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" android:layout_height="wrap_content"
 android:padding="4dip">

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:orientation="vertical" android:padding="4dip"
  android:layout_weight="1">

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" android:layout_height="wrap_content"
   android:orientation="horizontal" android:padding="4dip">
   <TextView android:id="@+id/reviewItemEntityName"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:textColor="@color/maroon" android:singleLine="true"
    android:ellipsize="end" android:textSize="14sp" android:textStyle="bold"
    android:layout_weight="1" />

   <ImageView android:id="@+id/reviewItemStarRating"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true" />
  </LinearLayout>

  <TextView android:id="@+id/reviewItemDescription"
   android:layout_width="fill_parent" android:layout_height="wrap_content"
   android:textSize="12sp" android:width="0dip" />
 </LinearLayout>


 <ImageView android:id="@+id/widget01" android:layout_width="wrap_content"
  android:layout_height="wrap_content" android:src="@drawable/arrow_nxt"
  android:layout_gravity="center_vertical" android:paddingRight="5dip" />

</LinearLayout>