Diseño de dos columnas con la primera columna wrap_content, second fill_parent
Tengo que diseñar IU para contener dos columnas.
La primera columna debe envolver la etiqueta contenida y la segunda en la misma fila debe llenar el espacio entero. A continuación algunos ejemplos:
- Estado de ahorro en widgets de vista compuesta
- ¿Cómo hacer que una vista de Android se desplace cuando aparece el teclado?
- ¿Cómo especificar el espaciado entre elementos de LinearLayout sólo una vez?
- Cómo establecer el ancho de la ListView en un PopupWindow en Android?
- Problema con el método setLayoutParams en la interfaz de usuario de Android
Http://temp.chrzanowski.info/so_layout.png
Cómo puedo hacer esto ?
- No es capaz de "findViewById" en Kotlin. Error de obtención "Inferencia de tipo no"
- El teclado Android se retrasa / es lento al cerrar usando adjustResize
- Cambio de fondo de una sola fila de gridview en android
- El contenido se empuja en la barra de herramientas cuando se utiliza animateLayoutChanges = "true"
- Android ScrollView no respeta el margen inferior del niño
- Android: Error en la clase R.java
- Alinear texto a la izquierda, marcar la casilla a la derecha
- View.setPadding acepta sólo en px, ¿hay de todos modos setPadding en dp?
Utilice TableLayout
con strechColumns = "1"
Se extiende la segunda columna ocupando el espacio restante.
<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>
Después de TableLayout
le daría la salida deseada:
<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's view --> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> <!-- second column's view --> </TableRow> ... </TableLayout>
Como alternativa, puede hacer un LinearLayout así:
<?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>
Para ajustar el ancho de las columnas, modifique el layout_weight
de cada contenedor LinearLayout. Menor valor significa menor ancho, y ambos pesos deben ser iguales a 100.
Prueba esto:
<?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>
- Android en el cambio de enfoque
- ¿Es posible iniciar una actividad en un apk diferente usando startActivity en Android usando el nombre de actividad o similar?