๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ๋ฆฌ๋‹ˆ์–ด ๋ ˆ์ด์•„์›ƒ(LinearLayout) 2๊ฐ€์ง€ ์ข…๋ฅ˜ ๋ณธ๋ฌธ

๐Ÿค–Android

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ๋ฆฌ๋‹ˆ์–ด ๋ ˆ์ด์•„์›ƒ(LinearLayout) 2๊ฐ€์ง€ ์ข…๋ฅ˜

๋ฃจ๋ฆฌ์•ผใ…‘ 2023. 12. 21. 18:01
๋ฐ˜์‘ํ˜•

์•ˆ๋“œ๋กœ์ด๋“œ์˜ LinearLayout์€ ํ™”๋ฉด์„ ๊ฐ€๋กœ ๋˜๋Š” ์„ธ๋กœ๋กœ ์ผ๋ ฌ๋กœ ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ ˆ์ด์•„์›ƒ์ด๋‹ค. ์ฃผ๋กœ ๋ทฐ๋“ค์„ ์ผ๋ ฌ๋กœ ๋ฐฐ์น˜ํ•˜๊ฑฐ๋‚˜, ์ค‘์ฒฉํ•˜์—ฌ ์‚ฌ์šฉํ•˜์—ฌ ํ™”๋ฉด์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐ ์œ ์šฉํ•˜๋‹ค. ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ LinearLayout์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

1. ์ˆ˜ํ‰ ๋ฐฉํ–ฅ(๊ฐ€๋กœ) LinearLayout

  • ๊ธฐ๋ณธ ๋ฐฉํ–ฅ์€ ์ˆ˜ํ‰.
  • android:orientation="horizontal"๋กœ ์„ค์ •ํ•˜๊ฑฐ๋‚˜, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ setOrientation(LinearLayout.HORIZONTAL)์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜ํ‰์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
  • ์ž์‹ ๋ทฐ๋“ค์„ ๊ฐ€๋กœ๋กœ ์ผ๋ ฌ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <!-- ์ˆ˜ํ‰์œผ๋กœ ๋ฐฐ์น˜๋  ์ž์‹ ๋ทฐ๋“ค -->

</LinearLayout>

[Android Emulator]

 

2. ์ˆ˜์ง ๋ฐฉํ–ฅ(์„ธ๋กœ) LinearLayout

  • android:orientation="vertical"๋กœ ์„ค์ •ํ•˜๊ฑฐ๋‚˜, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ setOrientation(LinearLayout.VERTICAL)์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜์ง์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
  • ์ž์‹ ๋ทฐ๋“ค์„ ์„ธ๋กœ๋กœ ์ผ๋ ฌ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- ์„ธ๋กœ๋กœ ๋ฐฐ์น˜๋  ์ž์‹ ๋ทฐ๋“ค -->

</LinearLayout>

[Android Emulator]

 

๋ฐ˜์‘ํ˜•