Android User Interface Design: Layout Basics
Android User Interface Design: Layout Basics
/* 0*)&1"2
3.4%5, 6.)&/)
LayouL
A Lype of resource LhaL denes whaL ls drawn on Lhe
screen. LayouL resources are sLored as xML les ln
Lhe /res/layouL resource dlrecLory for Lhe appllcauon.
A layouL resource ls slmply a LemplaLe for a user
lnLerface screen, or poruon of a screen, and conLaln.
A Lype of vlew class whose prlmary purpose ls Lo
organlze oLher conLrols. 1hese layouL classes
(LlnearLayouL, 8elauveLayouL, 1ableLayouL, eLc. ) are
used Lo dlsplay chlld conLrols, such as LexL conLrols or
buuons or lmages on Lhe screen.
ueslgn LayouL
ueslgn LayouL
use Lhe CuLllne pane Lo Add and 8emove
conLrols Lo your layouL resource.
SelecL a speclc conLrol (elLher ln Lhe revlew
or Lhe CuLllne) and use Lhe roperLy pane Lo
ad[usL a speclc conLrol's aurlbuLes.
use Lhe xML Lab Lo edlL Lhe xML denluon
dlrecLly.
uenlng an xML LayouL 8esource
xML layouL resources musL be sLored ln Lhe /res/layouL
pro[ecL dlrecLory (or, ln Lhe case of alLernauve
resources, ln a speclally named sub-dlrecLory).
lL's common pracuce Lo creaLe an xML layouL resource
for each screen ln your appllcauon (closely ued Lo a
speclc AcuvlLy), buL Lhls ls noL requlred.
?ou could, ln Lheory, creaLe an xML layouL resource
and use lL for dlerenL acuvlues, supplylng dlerenL
daLa on Lhe screen. ?ou can also componenuzed your
layouL resources and lnclude Lhem wlLhln one anoLher,
lf needed.
uenlng an xML LayouL 8esource
uenlng an xML LayouL 8esource
uenlng an xML LayouL 8esource
uenlng an xML LayouL 8esource
WlLhln Lhe AcuvlLy, only a slngle llne of code
wlLhln Lhe onCreaLe() meLhod ls necessary Lo
load and dlsplay a layouL resource on Lhe
screen. lf Lhe layouL resource was sLored ln
Lhe /res/layouL/maln.xml le, LhaL would be:
uenlng a LayouL rogrammaucally
LayouL 1ypes
7$.8*3.4%5, - deslgned Lo dlsplay a sLack of
chlld vlew conLrols. Muluple vlew conLrols can
be added Lo Lhls layouL. 1hls can be used Lo
show muluple conLrols wlLhln Lhe same screen
space.
3&"*.$3.4%5, - deslgned Lo dlsplay chlld vlew
conLrols ln a slngle row or column. 1hls ls a
very handy layouL meLhod for creaung forms.
LayouL 1ypes
9*:.;<*3.4%5, - deslgned Lo dlsplay chlld vlew
conLrols ln relauon Lo each oLher. lor lnsLance, you can
seL a conLrol Lo be posluoned above" or below" or
Lo Lhe le of" or Lo Lhe rlghL of" anoLher conLrol,
referred Lo by lLs unlque ldenuer. ?ou can also allgn
chlld vlew conLrols relauve Lo Lhe parenL edges.
=.>:*3.4%5, - deslgned Lo organlze chlld vlew
conLrols lnLo rows and columns. lndlvldual vlew
conLrols are added wlLhln each row of Lhe Lable uslng a
1able8ow layouL vlew (whlch ls baslcally a horlzonLally
orlenLed LlnearLayouL) for each row of Lhe Lable.
Worklng wlLh 8uuons
Worklng wlLh 8uuons
Pandle Cllcks
Pandle Cllcks
Pandle Cllcks - CnCllckLlsLener