user4824797
user4824797

Reputation: 41

How can I wrap text in text view with a table layout?

This is my code. I want the line "Telescopic with anti friction bush with Nitrox mono shock absorber with Canister" to be broken into two lines when width of the body ends.

    <TableRow
        android:background="#CCC"
        android:paddingBottom="1dp"
        android:paddingRight="1dp">
        <TextView
            android:layout_marginLeft="1dp"
            android:padding="5dp"
            android:background="#FFF"
            android:text="Rear"
             />
    <TextView
            android:layout_marginLeft="1dp"
            android:padding="5dp"
            android:background="#FFF"
            android:gravity="left"
            android:text="Telescopic with anti friction bush with Nitrox mono shock absorber with Canister"
            android:layout_width="wrap_content"/>
    </TableRow>

I also tried this text from values.xml file but problem is same. The column should adjust height according to text and width remain same.

Image link https://i.sstatic.net/JpCD5.jpg

Upvotes: 0

Views: 666

Answers (2)

Akash
Akash

Reputation: 11

<TableRow
    android:background="#CCC"
    android:paddingBottom="1dp"
    android:paddingRight="1dp">
    <TextView
        android:layout_marginLeft="1dp"
        android:padding="5dp"
        android:weight=".5"
        android:background="#FFF"
        android:text="Rear"/>
    <TextView
        android:layout_marginLeft="1dp"
        android:padding="5dp"
        android:background="#FFF"
        android:weight=".5"
        android:gravity="left"
        android:text="Telescopic with anti friction bush with Nitrox mono shock absorber with Canister"
        android:layout_width="wrap_content"/>
</TableRow>

Upvotes: 1

Jignesh Jain
Jignesh Jain

Reputation: 1568

try this

 <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#CCC"
        android:paddingBottom="1dp"
        android:paddingRight="1dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="1dp"
            android:background="#FFF"
            android:padding="5dp"
            android:text="Rear" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="1dp"
            android:background="#FFF"
            android:gravity="left"
            android:padding="5dp"
            android:text="Telescopic with anti friction bush with Nitrox mono shock absorber with Canister" />
    </TableRow>

Upvotes: 1

Related Questions