[Android ๊ธฐ์ดˆ] 5. UI ๊ธฐ๋ณธ ๊ฐœ๋… (Layout, Margin, Padding, Gravity, Style, Theme)
๋ฐ˜์‘ํ˜•

 

 

 

 


 

1. ๋ ˆ์ด์•„์›ƒ(Layout)

 

  • ๋ ˆ์ด์•„์›ƒ์ด๋ž€ ViewGroup์˜ ํŒŒ์ƒ ํด๋ž˜์Šค๋กœ์„œ, ํฌํ•จ๋œ View๋ฅผ ์ •๋ ฌํ•˜๋Š” ๊ธฐ๋Šฅ

 

 

 

 

01. Linear Layout

  • ์ปจํ…Œ์ด๋„ˆ์— ํฌํ•จ ๋œ ์ž์‹ ๋ทฐ๋“ค์„ ์ˆ˜ํ‰ ๋˜๋Š” ์ˆ˜์ง์œผ๋กœ ์ผ๋ ฌ ๋ฐฐ์น˜ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ
  • ๊ฐ€์žฅ ๋‹จ์ˆœํ•˜๊ณ  ์ง๊ด€์ ์ด๋ฉฐ ์‚ฌ์šฉ๋นˆ๋„๊ฐ€ ๋†’์Œ
  • Orientation : Vertical(Child๋ฅผ ์œ„์—์„œ ์•„๋ž˜๋กœ), Horizontal(child๋ฅผ ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ)
  • LinearLayout์˜ ์ž์‹(Children)์œผ๋กœ ๋ฐฐ์น˜๋˜๋Š” View์œ„์ ฏ๋“ค์€ ์˜ค์ง ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ๋ฐฐ์น˜
  • ์œ„์ ฏ์˜ ํฌ๊ธฐ (๋†’์ด ๋˜๋Š” ๋„ˆ๋น„) ์™€ ๊ด€๊ณ„์—†์ด ํ•œ ์ค„๋กœ๋งŒ ๋ฐฐ์—ด
    ๊ฐ€๋กœ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐฐ์น˜ ๋  ๋•Œ๋Š” ๊ฐ€๋กœ๋กœ ํ•œ ์ค„(onlyonerow), ์„ธ๋กœ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐฐ์น˜๋  ๋•Œ๋Š” ์„ธ๋กœ๋กœ ํ•œ ์ค„(onlyonecolumn)
  • LinearLayout์˜ ์ž์‹๋“ค์€ ์ค‘์ฒฉ(overlap)๋˜์ง€ ์•Š๊ณ ,์ง€์ •ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ์Œ“์ด๋Š”(stacked)ํ˜•ํƒœ๋กœ ํ‘œ์‹œ

 

๐Ÿ’ก LayoutWeight

  • ์ž์‹(Children)๋“ค์ด ๋ฐฐ์น˜ ๋  ๋•Œ, ์ „์ฒด ์˜์—ญ ๋Œ€๋น„ ๋น„์œจ์˜ ๊ฐœ๋…์œผ๋กœ ์ง€์ • ํ•  ์ˆ˜ ์žˆ๋Š” Weight(๊ฐ€์ค‘์น˜)๋ฅผ ์„ค์ • ๊ฐ€๋Šฅ
  • (์˜ˆ) ์ „์ฒด ํฌ๊ธฐ๋ฅผ 10์œผ๋กœ ๋ณธ๋‹ค๋ฉด, ์ฒซ ๋ฒˆ์งธ View ์œ„์ ฏ์€ 3, ๋‘ ๋ฒˆ์งธ View ์œ„์ ฏ์€ 7์˜ ์˜์—ญ์„ ์ฐจ์ง€ํ•˜๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ
  • android:layout_weight = "3"

 

 

 

 

02. Relative Layout

์ถœ์ฒ˜: recipes4dev.titory.com

  • ๋ทฐ๋ฅผ ์„œ๋กœ ๊ฐ„์˜ ์œ„์น˜ ๊ด€๊ณ„๋‚˜ ์ปจํ…Œ์ด๋„ˆ์™€์˜ ์œ„์น˜ ๊ด€๊ณ„๋ฅผ ์ง€์ •ํ•˜์—ฌ ๋ฐฐ์น˜ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ
  • 1. ์ž์‹(Children) View์œ„์ ฏ๋“ค์ด ์„œ๋กœ ๊ฐ„์˜ ์ƒ๋Œ€์  ๋ฐฐ์น˜ ๊ด€๊ณ„์— ๋”ฐ๋ผ ํ™”๋ฉด์— ํ‘œ์‹œ ๋  ์œ„์น˜๊ฐ€ ๊ฒฐ์ •
  • (์˜ˆ) B๋Š” A์˜ ์˜ค๋ฅธ์ชฝ์— ํ‘œ์‹œ : B toRightOf A
    (์˜ˆ) D๋ฅผ C์˜ ์•„๋ž˜์ชฝ์— ํ‘œ์‹œ : D below C
  • 2. View ์œ„์ ฏ๋“ค์„ ํฌํ•จํ•˜๋Š” ๋ถ€๋ชจ(Relative Layout) ์ž์ฒด๊ฐ€ ์ƒ๋Œ€์  ์œ„์น˜์˜ ๊ธฐ์ค€์ ์œผ๋กœ ์‚ฌ์šฉ ๋ ์ˆ˜๋„ ์žˆ์Œ
    (์˜ˆ) ์ž์‹(Children)๋“ค์— '์ƒ๋Œ€์ ์ธ' ๋ฐฐ์น˜ ๊ธฐ์ค€์„ ์ง€์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, RelativeLayout ๋‚ด๋ถ€์—์„œ ์ค‘์ฒฉ(Overlap)๋˜์–ด ํ‘œ์‹œ
  • ์‚ฌ์šฉ ์˜ˆ์‹œ
    - android:layout_toLeftOf="@id/buttion1"
    - android:layout_alignParentLeft="true"

 

  ์†์„ฑ ์„ค๋ช…
์ž์‹ ๊ฐ„ ๊ธฐ์ค€





layout_toLeftOf ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ์™ผ์ชฝ(Left)์— ๋ฐฐ์น˜
layout_above ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ์œ„(Above)์— ๋ฐฐ์น˜
layout_roRightOf ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ์˜ค๋ฅธ์ชฝ(Right)์— ๋ฐฐ์น˜
layout_below ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ์•„๋ž˜(Below)์— ๋ฐฐ์น˜
layout_toStartOf ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ์‹œ์ž‘(Start)์— ๋ฐฐ์น˜
layout_toEndOf ๋ทฐ(View)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(Anchor View)์˜ ๋(End)์— ๋ฐฐ์น˜
layout_alignLeft ๋ทฐ(View)์˜ ์™ผ์ชฝ(Left)์„ ๊ธฐ์ค€ ๋ทฐ(View)์˜ ์™ผ์ชฝ(Left)์— ๋งž์ถค.
layout_alignTop  ๋ทฐ(View)์˜ ์œ„(Top)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(View)์˜ ์œ„(Top)์— ๋งž์ถค.
layout_alignRight ๋ทฐ(View)์˜ ์˜ค๋ฅธ์ชฝ(Right)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(View)์˜ ์˜ค๋ฅธ์ชฝ(Right)์— ๋งž์ถค.
layout_alignBottom  ๋ทฐ(View)์˜ ์•„๋ž˜(Bottom)๋ฅผ ๊ธฐ์ค€ ๋ทฐ(View)์˜ ์•„๋ž˜(Bottom)์— ๋งž์ถค.
layout_alignBaseline  ๋ทฐ(View)์˜ ํฐํŠธ ๊ธฐ์ค€์„ (Baseline)์„ ๊ธฐ์ค€ ๋ทฐ(View)์˜ ํฐํŠธ ๊ธฐ์ค€์„ (Baseline)์— ๋งž์ถค.
๋ถ€๋ชจ ๊ธฐ์ค€

layout_alignParentLeft ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ ๋‚ด์—์„œ ์™ผ์ชฝ(Left)์— ๋ฐฐ์น˜
layout_alignParentTop ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ ๋‚ด์—์„œ ์œ„์ชฝ(Top)์— ๋ฐฐ์น˜
layout_alignParentRight ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ ๋‚ด์—์„œ ์˜ค๋ฅธ์ชฝ(Right)์— ๋ฐฐ์น˜
layout_alignParentBottom ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ ๋‚ด์—์„œ ์•„๋ž˜์ชฝ(Bottom)์— ๋ฐฐ์น˜
layout_centerHorizontal ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ์˜ ๊ฐ€๋กœ ๋ฐฉํ–ฅ ๊ฐ€์šด๋ฐ ๋ฐฐ์น˜.
layout_centerVertical ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ์˜ ์„ธ๋กœ ๋ฐฉํ–ฅ ๊ฐ€์šด๋ฐ ๋ฐฐ์น˜.
layout_centerInParent ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ์˜ ์ • ์ค‘์•™(center)์— ๋ฐฐ์น˜.
layout_alignParentStart ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ์˜ ์‹œ์ž‘ ์ง€์ (Start)์— ๋ฐฐ์น˜.
layout_alignParentEnd ๋ทฐ(View)๋ฅผ ๋ถ€๋ชจ(Parent) ์˜์—ญ์˜ ๋ ์ง€์ (End)์— ๋ฐฐ์น˜.

 

 

 

 

03. Table Layout

์ถœ์ฒ˜: ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ

  • ํ‘œ ํ˜•์‹์œผ๋กœ ์ฐจ์ผ๋“œ๋ฅผ ๋ฐฐ์น˜ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ
  • ์ž์‹(Children) View ์œ„์ ฏ๋“ค์„ ํ…Œ์ด๋ธ”(ํ–‰๊ณผ ์—ด๋กœ ๊ตฌ์„ฑ)๋กœ ๋‚˜๋ˆ„์–ด ํ‘œ์‹œ
  • ํ‘œ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ํ–‰์˜ ๊ฐœ์ˆ˜๋งŒํผ TableRow๋ฅผ ํฌํ•จํ•˜๊ณ , TableRow๋Š” ๊ฐ ํ–‰์— ํฌํ•จ๋œ ์…€(View)์„ ํฌํ•จ
  • ์ฃผ์š” ์†์„ฑ
    - stretchColumns: ๋Š˜๋ฆด ์—ด์„ ์ง€์ •
    - "*" : ๋ชจ๋“  ์—ด์„ ๋Š˜์—ฌ์„œ ๋ฐฐ์น˜
    - "1, 2" : 1์—ด(์™ผ์ชฝ์—์„œ 2๋ฒˆ์งธ)๊ณผ 2์—ด(์™ผ์ชฝ์—์„œ 3๋ฒˆ์งธ)๋ฅผ ๋Š˜์—ฌ์„œ ๋ฐฐ์น˜
  • TableRow
    - ์ •ํ•ด์ง„ ๊ทœ์น™์— ๋”ฐ๋ผ ํฌ๊ธฐ๊ฐ€ ๊ฒฐ์ •๋˜๋ฏ€๋กœ, layout_width/height๋ฅผ ์ง€์ •ํ•  ํ•„์š”๊ฐ€ ์—†์Œ
    - layout_height๋Š” ํ•ญ์ƒ wrap_content
    - layout_width๋Š” ํ•ญ์ƒ match_parent

 

 

 

 

 

04. Frame Layout

  • ์ปจํ…Œ์ด๋„ˆ์— ํฌํ•จ๋œ ๋ทฐ๋“ค์„ ์ „๋ถ€ ์ขŒ์ƒ๋‹จ์— ๋ฐฐ์น˜ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ
  • ํ•˜๋‚˜์˜ ์ž์‹ View์œ„์ ฏ๋งŒ ํ‘œ์‹œ ํ•  ๋•Œ ์‚ฌ์šฉ
    (์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ทฐ(View) ์œ„์ ฏ๋“ค์„ ์ค‘์ฒฉํ•˜๊ณ , ๊ทธ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ „๋ฉด์— ํ‘œ์‹œํ•  ๋•Œ. ํฌ์ŠคํŠธ์ž‡ ์œ„์— ๋ฎ๋Š” ๋Š๋‚Œ)
  • Frame Layout์— ์—ฌ๋Ÿฌ View์œ„์ ฏ์„ ์ž์‹์œผ๋กœ ์ถ”๊ฐ€ํ•˜๋ฉด ๊ฒน์ณ์ง„ ํ˜•ํƒœ(Overlap)๋กœ ํ‘œ์‹œ๋˜๋ฉฐ,
    ๊ฐ€์žฅ ์ตœ๊ทผ์— ์ถ”๊ฐ€๋œ View์œ„์ ฏ์ด ๊ฐ€์žฅ ๋งจ ์œ„, ์ƒ์œ„ (ontop) ์— ํ‘œ์‹œ

 

 

 

 

05. Constraint Layout

  • ์ œ์•ฝ ์กฐ๊ฑด์„ ์‚ฌ์šฉํ•ด ํ™”๋ฉด์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ
  • ๋ณต์žกํ•œ ๋ ˆ์ด์•„์›ƒ์„ ๋‹จ์ˆœํ•œ ๊ณ„์ธต๊ตฌ์กฐ๋ฅผ ์ด์šฉํ•ด ํ‘œํ˜„ ํ•  ์ˆ˜ ์žˆ๋Š” ViewGroup
  • ํ˜•์ œ View๋“ค๊ณผ์˜ ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•ด์„œ ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฑด RelativeLayout๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ ๋ณด๋‹ค ์œ ์—ฐ, ๋‹ค์–‘
    - RelativeLayout์—์„  ๋ถˆ๊ฐ€๋Šฅํ–ˆ๋˜ ์ž์‹ ๋ทฐ๊ฐ„์˜ ์ƒํ˜ธ ๊ด€๊ณ„ ์ •์˜ ๊ฐ€๋Šฅ
    - ๋ทฐ ๊ณ„์ธต์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์–ด ์œ ์ง€๋ณด์ˆ˜๋„ ์ข‹๊ณ  ์„ฑ๋Šฅ๋„ ์ข‹์Œ

 

 

 

์ฐจ๋ก€๋กœ ๋ฆฌ์‚ฌ์ด์ฆˆ ํ•ธ๋“ค, ์‚ฌ์ด๋“œ ํ•ธ๋“ค, ๋ฒ ์ด์Šค๋ผ์ธ ํ•ธ๋“ค

 

 

๐Ÿ’ก์œ„์ ฏ์˜ ํฌ๊ธฐ ์„ค์ •

  • ๋ฆฌ์‚ฌ์ด์ฆˆ ํ•ธ๋“ค (ResizeHandle) ์ด์šฉํ•˜๊ธฐ
    - ์œ„์ ฏ์„ ํด๋ฆญํ•˜๋ฉด ๋„ค ๋ชจ์„œ๋ฆฌ์— ํ•ธ๋“ค์ด ์ƒ๊ฒจ, ๋งˆ์šฐ์Šค๋กœ ๋“œ๋ž˜๊ทธํ•˜์—ฌ ํฌ๊ธฐ๋ฅผ ์„ค์ •
    - ๋“œ๋ž˜๊ทธํ•ด์„œ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๋ฉด ์˜ค๋ฅธ์ชฝ ์†์„ฑ์ฐฝ์˜ layout_width, layout_height ๋ฅผ ์ž…๋ ฅํ•ด์„œ ์„ค์ • ๊ฐ€๋Šฅ
  • ์ง์ ‘ ๊ฐ’์„ ์ž…๋ ฅํ•˜์—ฌ ์„ค์ •ํ•˜๊ธฐ
    - ์˜ค๋ฅธ์ชฝ ์†์„ฑ์ฐฝ์˜ layout_width, layout_height ๋ฅผ ์ž…๋ ฅํ•ด์„œ ์„ค์ • ๊ฐ€๋Šฅ
  • wrap_content : ์œ„์ ฏ ๋‚ด๋ถ€์— ์žˆ๋Š” ์ปจํ…์ธ ์— ๋”ฑ ๋งž๊ฒŒ ๊ธธ์ด ๊ฒฐ์ •
  • match_constraint : ๋„ˆ๋น„๋ฅผ ๊ฝ‰ ์ฑ„์šฐ๋„๋ก ๋Š˜์–ด๋‚จ

 

๐Ÿ’ก ์œ„์ ฏ์˜ ์ƒ๋Œ€ ์ •๋ ฌ

  • ์‚ฌ์ด๋“œ ํ•ธ๋“ค(SideHandle) ์ด์šฉํ•˜๊ธฐ
    - ์œ„์ ฏ์„ ํด๋ฆญํ•˜๋ฉด ๊ฐ ๋ณ€์˜ ๊ฐ€์šด๋ฐ ํ•ธ๋“ค์ด ์žˆ์Œ
    - ์œ„์ ฏ์ด ๋‹ค๋ฅธ ์œ„์ ฏ ๋˜๋Š” ํ™”๋ฉด์˜ ๊ฒฝ๊ณ„์— ๋Œ€ํ•ด ์–ด๋–ป๊ฒŒ ์ •๋ ฌ๋ ์ง€ ๋“œ๋ž˜๊ทธํ•˜์—ฌ ์—ฐ๊ฒฐ ๋ฐ ์ง€์ • ๊ฐ€๋Šฅ
  • ์šฐ์ธก ์†์„ฑ์ฐฝ์—์„œ ์ •๋ ฌ๊ฐ’ ์„ค์ • ๊ฐ€๋Šฅ

 

๐Ÿ’ก ์œ„์ ฏ ๋‚ด ํ…์ŠคํŠธ์˜ ์œ„์น˜๋กœ ์ •๋ ฌ

  • ๋ฒ ์ด์Šค๋ผ์ธ ํ•ธ๋“ค(BaselineHandle) ์ด์šฉํ•˜๊ธฐ
    - ์œ„์ ฏ์„ ํด๋ฆญํ•˜๊ณ  ๋งˆ์šฐ์Šค๋ฅผ ๊ฐ€์ ธ๊ฐ€๋ฉด ์ขŒ์ธก ํ•˜๋‹จ์— 'ab' ๋ผ๋Š” ๋ฒ ์ด์Šค๋ผ์ธ ์•„์ด์ฝ˜์ด ์žˆ์Œ
    - ํด๋ฆญํ•˜๋ฉด ์œ„์ ฏ์˜ ํ…์ŠคํŠธ ํ•˜๋‹จ์— ๋ฒ ์ด์Šค ๋ผ์ธ ํ•ธ๋“ค์ด ๋ณด์ž„
    - ์ด ๋ฒ ์ด์Šค ๋ผ์ธ ํ•ธ๋“ค์„ ํด๋ฆญํ•˜์—ฌ ๋‹ค๋ฅธ ์œ„์ ฏ์˜ ํ…์ŠคํŠธ์— ์—ฐ๊ฒฐํ•˜๋ฉด, ํ…์ŠคํŠธ์˜ ํ•˜๋‹จ์ด ์ผ์น˜ํ•˜๋„๋ก ์ •๋ ฌ

 

 

๐Ÿ’ก Constraint ํˆด๋ฐ” ์‚ฌ์šฉํ•˜๊ธฐ

์ถœ์ฒ˜: ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ

  • 1. Autoconnect
    - ์ผœ๋‘๋ฉด ์œ„์ ฏ์„ ๋ฐฐ์น˜ํ• ๋•Œ ์ž๋™์œผ๋กœ ์ด์›ƒํ•œ ์œ„์ ฏ๊ณผ ๊ด€๊ณ„๋ฅผ ๋งบ์–ด์คŒ
  • 2. Clear All Constraints
    - ๋ชจ๋“  ๊ด€๊ณ„๋ฅผ ์‚ญ์ œ
  • 3. Infer constraints
    - ๋ ˆ์ด์•„์›ƒ๋‚ด ๋ฐฐ์น˜๋œ ๋ชจ๋“  ์œ„์ ฏ์„ ํ˜„์žฌ ์œ„์น˜๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ด€๊ณ„๋ฅผ ๋งบ์–ด์คŒ
  • 4. Default Margins
    - ์œ„์ ฏ ๊ฐ„์˜ ๊ธฐ๋ณธ ๋งˆ์ง„ ๊ฐ’์„ ์ง€์ •
  • 5. Guidelines
    - ์ˆ˜ํ‰,์ˆ˜์ง ๊ฐ€์ด๋“œ๋ผ์ธ์„ ๋งŒ๋“ฆ
    - ์œ„์ ฏ์„ ์ด ๊ฐ€์ด๋“œ๋ผ์ธ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ ํ•  ์ˆ˜ ์žˆ์Œ

 

 

๐Ÿ’ก ์†์„ฑ์ฐฝ

  • 1. Margin
    - layout_width๊ฐ€ match_constraint์ด๋ฏ€๋กœ ์ขŒ์šฐ ์—ฌ๋ฐฑ 8๋งŒ ์žˆ๊ณ  ๋‚จ์€ ์ „์ฒด๋ฅผ ์œ„์ ฏ์ด ์ฐจ์ง€์ค‘
  • 2. Aspect Ratio
    - ํด๋ฆญํ•˜๋ฉด ์œ„์ ฏ์˜ ๊ฐ€๋กœ ์„ธ๋กœ๋น„์œจ์„ ์ง€์ •
  • 3. Wrap Content
    - ๋ถ€๋“ฑํ˜ธ ์„ธ ๊ฐœ(<<<)๋กœ ๋œ ๋ชจ์–‘์€ wrap_content๋กœ ์ง€์ •๋˜์–ด ์žˆ์Œ์„ ๋‚˜ํƒ€๋ƒ„
  • 4. Any Size
    - ํ†ฑ๋‹ˆ๋ชจ์–‘์€ ์ตœ๋Œ€ํ•œ์˜ ๋„ˆ๋น„๋ฅผ ์ฐจ์ง€, match_constraint๋กœ ์ง€์ •๋˜์–ด ์žˆ์Œ
  • 5. ์ ์„ 
    - ์•„๋ฌด ๊ด€๊ณ„๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ
  • 6. Horizontal Bias
    - ์œ„์ ฏ์˜ ์ขŒ์šฐ์ธก ์œ„์น˜ ๋น„์œจ์„ ์ง€์ •
    - ๋“œ๋ž˜๊ทธํ•ด์„œ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Œ

 

 

 

 

 


 

 

2. Margin / Padding / Gravity

 

 

์ถœ์ฒ˜: ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ

 

 

01. Margin

  • ๋ทฐ์™€ ๋‹ค๋ฅธ ๋ทฐ(์ปจํ…Œ์ด๋„ˆ) ๊ฐ„์˜ ๊ฐ„๊ฒฉ
  • android:layout_margin="" : ์ƒํ•˜์ขŒ์šฐ๋กœ ๋™์ผํ•œ ๋งˆ์ง„ ์„ค์ •์‹œ์— ์‚ฌ์šฉ๋˜๋Š” ์†์„ฑ
  • layout_marginLeft, layout_marginRight, layout_marginTop, layout_marginBottom
    : 4๋ฐฉํ–ฅ์˜ ๋งˆ์ง„์„ ๊ฐ๊ธฐ ๋‹ค๋ฅด๊ฒŒ ์„ค์ • ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ์†์„ฑ

 

 

02. Padding

  • ๋ทฐ ์•ˆ์˜ ๋‚ด๋ถ€์—ฌ๋ฐฑ
  • android:padding="": ์ƒํ•˜์ขŒ์šฐ๋กœ ๋™์ผํ•œ ํŒจ๋”ฉ ์„ค์ • ์‹œ์— ์‚ฌ์šฉ
  • paddingLeft, paddingRight, paddingTop, paddingBottom**
    : ๋ฐฉํ–ฅ์˜ ๋งˆ์ง„์„ ๊ฐ๊ธฐ ๋‹ค๋ฅด๊ฒŒ ์„ค์ • ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ์†์„ฑ**

 

 

03. Gravity

 

  • android:gravity="" ๋กœ ์‚ฌ์šฉ
  • gravity: ํ•ด๋‹น ๋ทฐ์•ˆ์˜ ๋‚ด์šฉ๋ฌผ ์œ„์น˜์— ๋Œ€ํ•œ ์ •๋ ฌ๋ฐฉ์‹์„ ์ง€์ •
  • layout_gravity: ๋ถ€๋ชจ ๋ทฐ ์•ˆ์—์„œ ํ•ด๋‹น ๋ทฐ์˜ ์ •๋ ฌ ๋ฐฉ์‹ ์ง€์ •
  • ๊ฐ€๋Šฅํ•œ ๊ฐ’๋“ค (๋ถ€๋ชจ ๋ทฐ ์•ˆ์—์„œ ํ•ด๋‹น ๋ทฐ์˜ ์ •๋ ฌ ๋ฐฉ์‹ ์ง€์ •๋งŒ)
    - BOTTOM : ­๋ถ€๋ชจ ๋ทฐ์—์„œ ์•„๋ž˜ ์ชฝ์— ์œ„์น˜์‹œํ‚ด
    - CENTER ­: ๋ถ€๋ชจ ๋ทฐ์˜ ์ค‘์•™์— ์œ„์น˜์‹œํ‚ด
    - CENTER_HORIZONTAL : ­๋ถ€๋ชจ ๋ทฐ์˜ ์ˆ˜ํ‰๊ธฐ์ค€์œผ๋กœ ์ค‘์•™์— ์œ„์น˜์‹œํ‚ด
    - CENTER_VERTICAL : ­๋ถ€๋ชจ ๋ทฐ์˜ ์ˆ˜์ง๊ธฐ์ค€์œผ๋กœ ์ค‘์•™์— ์œ„์น˜์‹œํ‚ด
    - END­ : ๋ถ€๋ชจ ๋ทฐ์—์„œ ํ…์ŠคํŠธ ๋ฐฉํ–ฅ์˜ ๋(ํ•œ๊ธ€์ด๋‚˜ ์˜์–ด์˜ ๊ฒฝ์šฐ๋Š” ์˜ค๋ฅธ์ชฝ)์— ์œ„์น˜์‹œํ‚ด
    - LEFT : ­๋ถ€๋ชจ ๋ทฐ์—์„œ ์™ผ์ชฝ์— ์œ„์น˜์‹œํ‚ด
    - RIGHT : ­๋ถ€๋ชจ ๋ทฐ์—์„œ ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜์‹œํ‚ด
    - TOP : ­๋ถ€๋ชจ ๋ทฐ์—์„œ ์œ„์ชฝ์— ์œ„์น˜์‹œํ‚ด

 

 


 

 

3. Style,Theme

 

 

01. Style

์œ„์™€ ๊ฐ™์ด styles.xml ํŒŒ์ผ ์ˆ˜์ • ํ›„, ๋ ˆ์ด์•„์›ƒ xml ํŒŒ์ผ์—์„œ ๋ฒ„ํŠผ ์•ˆ์— style ="@style/BtnStyle" ์ž…๋ ฅ

  • View ๋˜๋Š” ์ฐฝ์˜ ๋ชจ์–‘๊ณผ ํ˜•์‹์„ ์ง€์ •ํ•˜๋Š” ์†์„ฑ ๋ชจ์Œ
  • ๋†’์ด, ํŒจ๋”ฉ, ๊ธ€๊ผด ์ƒ‰์ƒ, ๊ธ€๊ผดํฌ๊ธฐ, ๋ฐฐ๊ฒฝ์ƒ‰ ๋“ฑ์˜ ์†์„ฑ์„ ์ง€์ •
  • ๋ ˆ์ด์•„์›ƒ์„ ์ง€์ •ํ•˜๋Š” XML๊ณผ ๋ณ„๊ฐœ์ธ XML๋ฆฌ์†Œ์Šค์— ์ •์˜๋จ
  • Android์˜ ์Šคํƒ€์ผ์€ ์›น ๋””์ž์ธ์˜ cascading์Šคํƒ€์ผ ์‹œํŠธ์™€ ์œ ์‚ฌํ•œ ์ฒ ํ•™์„ ๊ณต์œ 
  • ์ด๋ฅผ ํ†ตํ•ด ์ฝ˜ํ…์ธ ์™€ ๋””์ž์ธ์„ ๊ตฌ๋ถ„

 

 

02. Theme (ํ…Œ๋งˆ)

  • ๊ฐœ๋ณ„View ๊ฐ€ ์•„๋‹ˆ๋ผ ์ „์ฒด Activity ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ์šฉ๋˜๋Š” ์Šคํƒ€์ผ
  • ์Šคํƒ€์ผ์ด ํ…Œ๋งˆ๋กœ ์ ์šฉ๋œ ๊ฒฝ์šฐ, ์•กํ‹ฐ๋น„ํ‹ฐ ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ํฌํ•จ๋œ ๋ชจ๋“  ๋ทฐ๊ฐ€ ์ž์‹ ์ด ์ง€์›ํ•˜๋Š” ์Šคํƒ€์ผ ์†์„ฑ์„ ์ ์šฉ
    (์˜ˆ) ์•กํ‹ฐ๋น„ํ‹ฐ์˜ ํ…Œ๋งˆ์™€ ๋™์ผํ•œ CodeFont์Šคํƒ€์ผ์„ ์ ์šฉํ•œ๋‹ค๋ฉด,
    ํ•ด๋‹น ์•กํ‹ฐ๋น„ํ‹ฐ์— ํฌํ•จ๋œ ๋ชจ๋“  ํ…์ŠคํŠธ์— ๋…น์ƒ‰์˜ ๊ณ ์ • ํญ ๊ธ€๊ผด์ด ์ ์šฉ

 

 

์‹ค์Šต

๋”๋ณด๊ธฐ

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#540BA6"
    tools:context=".MainActivity">



        <LinearLayout
        android:background="#E4C5FF"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button1"
            />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2"
            android:layout_gravity="center"
            />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button3"
            android:layout_gravity="right"
            />

    </LinearLayout>



        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#AB78B6"
            android:layout_margin="10dp">


            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button4"
                android:layout_toLeftOf="@id/button5"
                android:layout_marginRight="20dp"
                />

            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button5"
                android:layout_alignParentRight="true"
                />

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button6"
                android:layout_below="@id/button4"
                android:layout_marginLeft="10dp"
                />

        </RelativeLayout>




        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:background="#E4C5FF"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button7"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />

            <Button
                android:id="@+id/button8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Button8"
                app:layout_constraintStart_toEndOf="@id/button7"
                app:layout_constraintTop_toTopOf="@id/button7"
                app:layout_constraintBottom_toBottomOf="@id/button7"
                android:layout_marginLeft="20dp"
                />

            <Button
                android:id="@+id/button9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="Button9"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button7"
                />


        </androidx.constraintlayout.widget.ConstraintLayout>


<!--    </LinearLayout>-->


</LinearLayout>

 

 

 

 

๋ฐ˜์‘ํ˜•
 ๐Ÿ’ฌ C O M M E N T