En androide cada etiqueta en el archivo XML contiene dos atributos importantes:
- android: layout_width
- android: layout_height
Este atributo puede llegar a toma el valor wrap_content o fill_parent y este valor especificar la altura o la anchura de la vista solicitada.
Para entenderlos mejor, veamos sus definiciones:
- wrap_content: Este componente se muestra lo suficientemente grande como para incluir su contenido solamente.
- fill_parent: El componente se muestra tan grande como su padre, y rellenar los espacios restantes. (match_parent renombrado en el Nivel API 8).
Vamos a ver unos cuantos ejemplo para entenderlos mejor:
Usando en el botón:
Usando en el botón:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Modificamos el archivo activity_main.xml de android studio y creamos un botón básico dentro LinearLayout y cambiar los valores de los atributos de android: layout_width y android: layout_height:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/boton_prueba"
android:text="Boton Prueba"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Usando en el botón:
android:layout_width="match_parent"
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/boton_prueba"
android:text="Boton Prueba"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Usando en el botón:
android:layout_width="wrap_content"
android:layout_height="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/boton_prueba"
android:text="Boton Prueba"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
Y por ultimo Usando en el botón: match_parent y match_parent
android:layout_width="match_parent"
android:layout_height="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/boton_prueba"
android:text="Boton Prueba"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>