You are on page 1of 7

Compartir

Ms

Siguiente blog

Crear un blog

Acceder

El blog de Jos Antonio Quiles


Follana (joseanquiles)

VISITAS:

3 3 6 2 3
Sgueme por mail
Submit

jueves, 25 de octubre de 2012

ANDROID: Ejercicios para crear layouts


Ejercicio 1

Buscar este blog


Buscar

Archivo del blog


2013 (10)
2012 (11)
octubre (5)
ANDROID: Ejercicios para crear
layouts
ANDROID: Soporte para mltiples
pantallas
ANDROID: Layouts
ANDROID: Atributos para posicionar
las vistas
ANDROID: Resoluciones, pixels,
densidad...

abril (1)
febrero (1)
enero (4)

2011 (15)
2010 (5)

Fila de cuatro botones horizontalmente ocupando todo el ancho de la


pantalla. Cada botn tiene que ocupar el mismo espacio, o sea, el 25%
del ancho de la pantalla.
Dejar un espacio alrededor del grupo de botones de 20dp. Separar entre s
cada uno de los botones por 5dp.

2009 (10)

Solucin

Seguidores
Participar en este sitio
Google Friend Connect

Miembros (7)

Ya eres miembro? Iniciar sesin

Datos personales
joseanquiles
Ver todo mi perfil

<LinearLayout xmlns:android="http://schemas.android.com/apk/res
/android" xmlns:tools="http://schemas.android.com
/tools" android:layout_width="match_parent" android:layout_height="mat
ch_parent" android:orientation="horizontal" android:padding="20dp">
<Button android:layout_height="wrap_content" android:layout_width="m
atch_parent" android:layout_weight="1" android:layout_margin="5dp" andr
oid:text="Botn 1" />
<Button android:layout_height="wrap_content" android:layout_width="m
atch_parent" android:layout_weight="1" android:layout_margin="5dp" andr
oid:text="Botn 2" />
<Button android:layout_height="wrap_content" android:layout_width="m
atch_parent" android:layout_weight="1" android:layout_margin="5dp" andr
oid:text="Botn 3" />
<Button android:layout_height="wrap_content" android:layout_width="m
atch_parent" android:layout_weight="1" android:layout_margin="5dp" andr
oid:text="Botn 4" />
</LinearLayout>

Explicacin
Con un LinearLayout horizontal ponemos los 4 botones en una fila.
El padding de 20dp en el LinearLayout pone un espacio interno para su
contenido (los botones).
Cada botn tiene un weight de 1 para que sean todos iguales dentro del
padre.
El margin de 5dp en los botones hace que stos queden separados entre s
por 5dp.

Ejercicio 2
Dividir la pantalla verticalmente en dos mitades. En la mitad superior
superior, colocar una imagen que ocupe toda la parte superior. En la mitad
inferior colocar un texto largo que permita desplazarse con scroll para
poder visualizarlo.Ambas mitades deben estar rodeadas de un margen de
5dp.

Solucin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res
/android" xmlns:tools="http://schemas.android.com
/tools" android:layout_width="match_parent" android:layout_height="mat
ch_parent" android:orientation="vertical" android:padding="5dp">
<ImageView android:layout_width="match_parent" android:layout_height
="match_parent" android:scaleType="fitCenter" android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ScrollView android:layout_width="match_parent" android:layout_height
="match_parent" android:layout_weight="1">
<TextView android:layout_width="match_parent" android:layout_height
="wrap_content" android:text="@string/texto" />
</ScrollView>
</LinearLayout>

Ejercicio 3
Un botn que ocupe el 50% del ancho de la pantalla y que est centrado
vertical y horizontalmente en la pantalla.

Solucin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res
/android" xmlns:tools="http://schemas.android.com
/tools" android:layout_width="match_parent" android:layout_height="mat
ch_parent" android:orientation="horizontal" android:gravity="center" andr
oid:weightSum="100">
<Button android:layout_width="0dp" android:layout_height="wrap_conte
nt" android:layout_weight="50" android:text="Botn" />
</LinearLayout>

Ejercicio 4
Construir el siguiente formulario:

Solucin
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res
/android" xmlns:tools="http://schemas.android.com
/tools" android:layout_width="match_parent" android:layout_height="mat
ch_parent" android:layout_marginTop="5dp" android:stretchColumns="1">
<TableRow>
<TextView android:text="Nombre (*)" android:layout_width="wrap_cont
ent" android:layout_height="wrap_content" />
<EditText android:layout_width="match_parent" android:layout_height=
"wrap_content" android:layout_margin="6dp" />
</TableRow>
<TableRow>
<TextView android:text="Apellido (*)" android:layout_width="wrap_cont
ent" android:layout_height="wrap_content" />
<EditText android:layout_width="match_parent" android:layout_height=
"wrap_content" android:layout_margin="6dp" />
</TableRow>
<TableRow>
<TextView android:text="e-mail (*)" android:layout_width="wrap_conte
nt" android:layout_height="wrap_content" />

<EditText android:layout_width="match_parent" android:layout_height=


"wrap_content" android:layout_margin="6dp" />
</TableRow>
<TableRow>
<TextView android:text="Mensaje" android:layout_width="wrap_content
" android:layout_height="wrap_content" />
<EditText android:layout_width="match_parent" android:layout_height=
"wrap_content" android:layout_margin="6dp" android:paddingRight="5dp"
android:inputType="textMultiLine" android:lines="3" />
</TableRow>
<LinearLayout android:layout_width="wrap_content" android:layout_heig
ht="wrap_content">
<CheckBox android:layout_width="wrap_content" android:layout_height
="wrap_content" android:text="Suscribirse por e-mail" android:checked="tr
ue" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_heig
ht="wrap_content" android:layout_marginTop="10dp">
<TextView android:text="Web del vendedor" android:layout_width="wra
p_content" android:layout_height="wrap_content" android:textColor="#00
00FF" android:textStyle="bold" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content" android:layout_heig
ht="wrap_content" android:layout_marginTop="20dp" android:gravity="cen
ter" android:orientation="horizontal">
<Button android:layout_width="wrap_content" android:layout_height="
wrap_content" android:text="Confirmar" />
<Button android:layout_width="wrap_content" android:layout_height="
wrap_content" android:text="Cancelar" />
</LinearLayout>
</TableLayout>
Publicado por joseanquiles en 12:26

No hay comentarios:

Publicar un comentario en la entrada

Comentar como:
Publicar

Seleccionar perfil...

Vista previa

Enlaces a esta entrada


Crear un enlace

Entrada ms reciente

Pgina principal

Suscribirse a: Enviar comentarios (Atom)

Entrada antigua

You might also like