λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
  • μž₯원읡 κΈ°μˆ λΈ”λ‘œκ·Έ
🀷🏼‍♀️ Etc.../- C, C++, Python, Android

[μ•ˆλ“œλ‘œμ΄λ“œ μŠ€νŠœλ””μ˜€] λ ˆμ΄μ•„μ›ƒ 닀루기 1. λ¦¬λ‹ˆμ–΄ λ ˆμ΄μ•„μ›ƒ(Linear Layout)

by Wonit 2020. 5. 1.

LinearLayout

λ¦¬λ‹ˆμ–΄ λ ˆμ΄μ•„μ›ƒμ€ κ°€μž₯ 많이 μ‚¬μš©λ˜λŠ” λ ˆμ΄μ•„μ›ƒ 으둜, μ™Όμͺ½ μœ„ -> μ•„λž˜, μ™Όμͺ½ μœ„ -> 였λ₯Έμͺ½μœΌλ‘œ μ°¨λ‘€λŒ€λ‘œ λ°°μΉ˜λ˜λŠ” λ ˆμ΄μ•„μ›ƒμ΄λ‹€.

좜처 : https://stackoverrun.com/ko/q/11355733

λ ˆμ΄μ•„μ›ƒμ— κ³΅ν†΅μ μœΌλ‘œ μ μš©λ˜λŠ” 속성이 μžˆλŠ”λ° λ‹€μŒκ³Ό κ°™λ‹€.

 

곡톡 속성

  • orientation : λ ˆμ΄μ•„μ›ƒ λ‚΄μ˜ μœ„μ ―μ˜ 수직 λ˜λŠ” μˆ˜ν‰ λ°©ν–₯을 μ„€μ •
  • gravity : λ ˆμ΄μ•„μ›ƒ λ‚΄μ˜ μœ„μ ―μ˜ μ •λ ¬ λ°©ν–₯을 μ„€μ •
  • padding : λ ˆμ΄μ•„μ›ƒ λ‚΄μ˜ μœ„μ ―μ˜ μ—¬λ°± μ„€μ •
  • layout_weight : λ ˆμ΄μ•„μ›ƒμ΄ 전체 ν™”λ©΄μ—μ„œ 차지할 κ³΅κ°„μ˜ κ°€μ€‘κ°’μœΌλ‘œ, μ—¬λŸ¬ λ ˆμ΄μ•„μ›ƒμ΄ 쀑볡될 λ•Œ μ‚¬μš©
  • baselineAligned : λ ˆμ΄μ•„μ›ƒ μ•ˆμ— λ°°μΉ˜ν•  μœ„μ ―μ„ 보기 μ’‹κ²Œ μ •λ ¬

 

orientation

 

λ ˆμ΄μ•„μ›ƒμ˜ (수직, μˆ˜ν‰)μ •λ ¬ 방식을 μ •ν•˜λŠ” layout_orientation 속성은 2 개의 값이 올 수 μžˆλ‹€.

  1. vertical
  2. horizontal

 

vertical

vertical μ˜΅μ…˜μ€ 수직으둜 contentλ₯Ό λ°°μΉ˜ν•œλ‹€.

vertical

 

XML μ½”λ“œ


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

</LinearLayout>

 

horizontal

horizontal μ˜΅μ…˜μ€ μˆ˜ν‰μœΌλ‘œ contentλ₯Ό λ°°μΉ˜ν•œλ‹€.

horizontal

XML μ½”λ“œ


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

</LinearLayout>

 

gravity

gravity μ˜΅μ…˜μ€ λ ˆμ΄μ•„μ›ƒ λ‚΄μ—μ„œ μœ„μ ―μ„ 어디에 λ°°μΉ˜ν• κΉŒ? 에 λŒ€ν•œ 결정을 ν•  수 있게 ν•œλ‹€.

κ²°μ • κ°’μœΌλ‘œλŠ” λ‹€μŒκ³Ό 같은 값이 μ˜¨λ‹€

  • left
  • right
  • center
  • bottom
  • top

λ˜ν•œ 2개λ₯Ό μ‘°ν•©ν•΄μ„œ right|bottom처럼 값을 쀄 수 μžˆλ‹€.
XML μ½”λ“œ


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="right">

</LinearLayout>

λŒ“κΈ€