Layout of two columns with first column wrap_content, second fill_parent

I need to develop an interface containing two columns.

The first column should contain a label, and the second in the same row should fill the entire space. The following is an example:

http://temp.chrzanowski.info/so_layout.png

How can i do this?

+4
source share
4 answers

Use TableLayout with strechColumns = "1"

It stretches the second column, occupying the remaining space.

 <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </TableRow> </TableLayout> 
+6
source

After TableLayout you will get the desired result:

 <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"> <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bla bla bla" android:singleLine="true" /> <!-- first column view --> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> <!-- second column view --> </TableRow> ... </TableLayout> 
+2
source

Alternatively, you can make LinearLayout as follows:

 <?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="wrap_content" android:orientation="horizontal" android:weightSum="100" android:gravity="center_vertical"> <LinearLayout android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="40"> <TextView android:layout_weight="1" android:layout_width="0dip" android:layout_height="wrap_content" android:text="A very very very long text" android:singleLine="true" android:scrollHorizontally="true" android:ellipsize="end"> </TextView> </LinearLayout> <LinearLayout android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="60"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="TextBox"> </EditText> </LinearLayout> </LinearLayout> 

To adjust the column widths, change the layout_weight each LinearLayout container. A small value means a smaller width, and both weights should be 100.

0
source

Try the following:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Label 1" android:layout_marginLeft="7dp" android:layout_marginTop="20dp"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Label Loooong2" android:layout_marginLeft="7dp" android:layout_marginTop="30dp"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Label 3" android:layout_marginLeft="7dp" android:layout_marginTop="30dp"/> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:orientation="vertical"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="TextBox"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="TextBox"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="TextBox"/> </LinearLayout> </LinearLayout> 
-1
source

All Articles