Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableRow not wrapping TextView

TableLayout has a TextView and EditText on each row. When EditText has a multiple row, TableRow wraps it but when TextEdit, it doesn't..

Simplyfied layout:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*" >

    <TableRow>

        <TextView
            android:id="@+id/textView1"
            android:text="Lorem ipsum dolor sit amet, consectetur" />

        <EditText
            android:id="@+id/textView2"
            android:text="Foo" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/textView3"
            android:text="Foo" />

        <EditText
            android:id="@+id/textView4"
            android:text="Lorem ipsum dolor sit amet, consectetur" />
    </TableRow>

</TableLayout>

Renders:Render 1

But when both controls are TextEdit, it renders correctly.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*" >

    <TableRow>

        <TextView
            android:id="@+id/textView1"
            android:text="Lorem ipsum dolor sit amet, consectetur" />

        <TextView
            android:id="@+id/textView2"
            android:text="Foo" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/textView3"
            android:text="Foo" />

        <TextView
            android:id="@+id/textView4"
            android:text="Lorem ipsum dolor sit amet, consectetur" />
    </TableRow>

</TableLayout>

Renders as: Render 2

What should i do for Android to render first layout correctly?

Ps: I have already tried to add android:layout_width="fill_parent",android:layout_height="wrap_content" attributes to TableRow, TextView, EditText controls, nothing has changed.

like image 617
hkutluay Avatar asked Dec 11 '12 07:12

hkutluay


2 Answers

I had the same problem and what solved everything was setting a weight to the textviews i wanted to word wrap.

My two cents...

like image 119
kekolab Avatar answered Sep 20 '22 21:09

kekolab


<?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="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="1dp"
            android:orientation="vertical"
            android:weightSum="4" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="1dp"
                android:layout_weight="1"
                android:background="#B0B0B0" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#B0B0B0" />
        </TableRow>
    </TableLayout>

</LinearLayout>

these Gray cells r textboxes

enter image description here

like image 25
Nipun Gogia Avatar answered Sep 22 '22 21:09

Nipun Gogia