1

hello i am trying to wrap a textview that has a long text. but when i test it, it just goes beyond the screen. What im trying to do is it will go to the next line if the text is long and it automatically adjust the layout. I am using this in a listview.

i am referring to this old question Android TextView Text not getting wrapped, it works on him so i tried to implement it but it wont effect on mine. thanks for answering.

here's my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:background="#e6e6e6"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <LinearLayout
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:orientation="vertical" android:padding="4dip"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_reviewer_name"
            android:textSize="16sp"
            android:textAppearance="?android:textAppearanceLarge"
            android:text="Reviewer Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_marginTop="5dp"
            android:id="@+id/tv_review_details"
            android:textSize="16sp"
            android:textAppearance="?android:textAppearanceSmall"
            android:text="Review"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:width="0dip"/>

    </LinearLayout>



</LinearLayout>

UPDATE

here's my listview:

<ListView
            android:divider="@android:color/transparent"
            android:dividerHeight="2.0sp"
            android:id="@+id/lv_reviews"
            android:background="#f2f2f2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
Community
  • 1
  • 1
Jarvis Millan
  • 451
  • 1
  • 7
  • 19

4 Answers4

0

You can use the inputType to auto manage a multiline text.

    <TextView
        android:layout_marginTop="5dp"
        android:id="@+id/tv_review_details"
        android:textSize="16sp"
        android:textAppearance="?android:textAppearanceSmall"
        android:text="Review"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:width="0dip"
        android:inputType="textMultiLine"
   />
Sadiq Md Asif
  • 882
  • 6
  • 18
0

if i use listView or recyclerView, i well put the layout width match parent as mentioned below:

<LinearLayout
           <!--change to match_parent-->
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" android:padding="4dip"
            android:layout_weight="1">

try it once, hope this will help you.

RPB
  • 16,006
  • 16
  • 55
  • 79
Morton
  • 5,380
  • 18
  • 63
  • 118
0

problem solved. it turns out android studio didnt update my changes when i ran my app. i uninstalled the app and then run it again and it works perfectly.

Jarvis Millan
  • 451
  • 1
  • 7
  • 19
0

When you are using Gravity in vertical orientation, you have to use layout_height=0dp & when you are using Gravity in Horizontal orientation then you have to use layout_width=0dp for every child of Linear Layout so that it can resize the layout by itself

<LinearLayout
    android:background="#e6e6e6"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <LinearLayout
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:orientation="vertical" android:padding="4dip"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_reviewer_name"
            android:textSize="16sp"
            android:textAppearance="?android:textAppearanceLarge"
            android:text="Reviewer Name"
            android:layout_width="wrap_content"
            android:layout_height="0dp" />

        <TextView
            android:layout_marginTop="5dp"
            android:id="@+id/tv_review_details"
            android:textSize="16sp"
            android:textAppearance="?android:textAppearanceSmall"
            android:text="Review"
            android:layout_height="0dp"
            android:layout_width="match_parent"/>

    </LinearLayout>



</LinearLayout>
Ashish Gupta
  • 737
  • 11
  • 18