Cómo establecer el peso para los diseños incluidos?
Tengo dos archivos xml, encabezado y pie de página como se muestra a continuación
Header.xml
- Layout_weight trabajo opuesto de lo que debería
- Diseño lineal y peso en Android
- Problemas de la suma de peso de TableLayout
- Android ¿Cómo setWeight de una RemoteView?
- Peso especificado ListView reduce el tamaño cuando se elimina el elemento
<?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="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#9d1246" > <Button android:id="@+id/button_backfromreg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:background="@drawable/backbtn" android:visibility="visible" /> </LinearLayout> </LinearLayout>
Footer.xml
<?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="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#9d1246" > </LinearLayout> </LinearLayout>
He incluido los dos diseños anteriores en mi mainlayout como se muestra
<?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:background="#eaedf2" android:orientation="vertical" > <include android:layout_weight="1" layout="@layout/header" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="30dp" android:layout_weight="1" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="Country" android:textColor="#655e5e" android:textSize="15sp" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="State" android:textColor="#655e5e" android:textSize="15sp" /> <EditText android:id="@+id/editText3" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="Place Keyword" android:textColor="#655e5e" android:textSize="15sp" /> </LinearLayout> <include android:layout_height="0dp" android:layout_weight="1" layout="@layout/footer" /> </LinearLayout>
Mi problema es que, usando el diseño anterior no puedo ver el pie de página. Cualquier persona por favor me ayude. Gracias por adelantado.
- Peso anidado en disposición lineal
- Android Linear Layout de peso mediante programación
- Establecer pesos de la vista mediante programación
- Creación de una cuadrícula como diseño en Android
Mantenga el diseño incluido en un contenedor y establezca el atributo de peso en ese contenedor únicamente.
Este es su diseño actualizado
<?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:background="#eaedf2" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <include android:layout_height="match_parent" android:layout_width="match_parent" layout="@layout/header" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="30dp" android:layout_weight="1" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="Country" android:textColor="#655e5e" android:textSize="15sp" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="State" android:textColor="#655e5e" android:textSize="15sp" /> <EditText android:id="@+id/editText3" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false" android:ems="10" android:hint="Place Keyword" android:textColor="#655e5e" android:textSize="15sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <include android:layout_height="match_parent" android:layout_width="match_parent" layout="@layout/footer" /> </LinearLayout> </LinearLayout>
En su pie juego match_parent para la altura ..
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#9d1246" > </LinearLayout>
Pruebe esto dando weightSum = "3"
al parentLayout
<?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:background="#eaedf2" android:orientation="vertical" android:weightSum="3" >
Y también añadir params a la include
<include android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" layout="@layout/header" /> <include android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" layout="@layout/footer" />
Espero que esto funcione