Beruflich Dokumente
Kultur Dokumente
Interfaces grficas
Viso geral
Classe
A
View
Desenha
Widgets
Classe
O que a View
Tipos de componentes:
Widgets
Gerenciadores
de layout
A classe ViewGroup
Drawable:
Identificadores:
Definio: android:id="@+id/identificador"
Referncia: android:layout_below="@id/identificador"
Strings:
android:src="@drawable/nome_drawable"
android:text="@string/nome_string"
Cores:
Estilos:
style="@style/nome_estilo
Via
cdigo da API
FrameLayout
FrameLayout
FrameLayout
Atributos
Exerccio - FrameLayout
Crie um projeto chamado LayoutSamples
Substitua o contedo de main.xml por:
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/smile" />
</FrameLayout>
10
LinearLayout
Propriedades
11
LinearLayout
12
LinearLayout
Atributos
Pesos
13
Exerccio - LinearLayout
</LinearLayout>
14
TableLayout
filho do LinearLayout e pode ser utilizado para
organizar os componentes em uma tabela, com linhas
e colunas.
Organiza componentes em linhas e colunas
Cada linha um TableRow (subclase de LinearLayout)
Propriedades
stretchColumns:
15
TableLayout
16
TableLayout
Atributos
17
Exerccio - TableLayout
<TableRow>
<TextView android:text="Produto B" android:background="#808080"/>
<TextView android:text="R$ 100,00" android:gravity="right" />
</TableRow>
</TableLayout>
(continua...)
18
Exerccio - TableLayout
<View android:layout_width="wrap_content"
android:layout_height="2px"
android:background="#000000" />
<TableLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1" >
<TableRow>
<TextView android:text="Produto A" />
<TextView android:text="Descrio curta" />
</TableRow>
<TableRow>
<TextView android:text="Produto B" />
<TextView android:text="Este produto possui
uma descrio muito grande e no caberia
na tela normalmente"
android:background="#808080"/>
</TableRow>
</TableLayout>
</LinearLayout>
19
RelativeLayout
Permite posicionar um componente relativo a outro
(abaixo, acima ou ao lado de um componente j
existente).
Componentes precisam ser identificados:
android:id="@+id/id_componente"
Propriedades
layout_below : Posiciona o elemento abaixo do indicado
layout_above : Posiciona o elemento acima do indicado
layout_toRightOf : Posiciona o elemento a direita do indicado
layout_toLeftOf: Posiciona o elemento a esquerda do indicado
20
RelativeLayout
layout_alignParentTop
indicado
layout_alineParentBotton
indicado
layout_marginTop
layout_marginRight
layout_marginLeft
21
RelativeLayout
22
RelativeLayout
Atributos
23
Exerccio - RelativeLayout
AbsoluteLayout
Propriedades
layout_x
layout_y:
25
AbsoluteLayout
26
AbsoluteLayout
Atributos
27
Dimenses
Dimenso
Descrio
px (pixels)
in (polegadas)
mm (milmetro)
pt (pontos_
1 pt = 1/72 in.
dp/dip
sp
28
Exerccio - AbsoluteLayout
android:layout_height="fill_parent">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Texto1"
android:layout_x="45px"
android:layout_y="87px" />
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Texto2"
android:layout_x="90px"
android:layout_y="12px" />
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Texto 3"
android:layout_x="90px"
android:layout_y="250px" />
</AbsoluteLayout>
29
Layout composto
30
31
Exerccio - ComplexLayout
Exerccio - ComplexLayout
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
android:layout_x="120px" android:layout_y="12px" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
android:layout_x="120px" android:layout_y="123px">
</Button>
</AbsoluteLayout>
<LinearLayout android:orientation="vertical">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="View"
</LinearLayout>
</TableRow>
</TableLayout>
33
/>
/>
/>
/>