TableRow not wrapping TextView

TableLayout has a TextView and an EditText for each row. When an EditText has multiple rows, a TableRow wraps it, but when a TextEdit , it does not ...

Nice 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 displays 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> 

Refers to: Render 2

What should I do for Android to display the first layout correctly?

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

+4
source share
4 answers
 <?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 are r text fields

enter image description here

+2
source

I had the same problem, and everything that solved, set the weight of the text views that I wanted to describe.

My two cents ...

+5
source

in TableLayout try adding

  android:stretchColumns="*" 

and if tat doesn't work either, try adding scales

  <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" > And to the TextView and EditText add android:layout_weight="1" 
+1
source

Adding android:layout_gravity="center_vertical" to a TextView or adding android:background="#B0B0B0" to an EditText causes android to render correctly.

+1
source

All Articles