1. Margin
: view์ ๋ค๋ฅธ ๋ทฐ(์ปจํ ์ด๋) ๊ฐ์ ๊ฐ๊ฒฉ
- ์ํ์ข์ฐ๋ก ๋์ผํ ๋ง์ง ์ค์ ์์ ์ฌ์ฉ๋๋ ์์ฑ : layout_margin
- 4๋ฐฉํฅ์ ๋ง์ง์ ๊ฐ๊ฐ ๋ค๋ฅด๊ฒ ์ค์ ํ ๋
: layout_marginLeft, layout_marginRight, layout_marginTop, layout_marginBottom
2. Padding
: ์ํ์ข์ฐ๋ก ๋์ผํ ํจ๋ฉ ์ค์ ์์ ์ฌ์ฉ (์์ชฝ์ผ๋ก!) : padding
- 4๋ฐฉํฅ์ ๋ง์ง์ ๊ฐ๊ฐ ๋ค๋ฅด๊ฒ ์ค์ ์
: paddingLeft, paddingRight, paddingTop, paddingBottom

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout ...
android:orientation="vertical"
>
<LinearLayout
android:layout_width="math_parent"
android:layout_height="marth_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_margin="40dp"
android:padding="20dp"
android:background="#aa00ff"
>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button"/>
</LinearLayout>
...
</LinearLayout>

3. Gravity
1) Gravity ์์ฑ : ํด๋น ๋ทฐ ์์ ๋ด์ฉ๋ฌผ(ํ ์คํธ) ์์น์ ๋ํ ์ ๋ ฌ ๋ฐฉ์์ ์ง์
2) layout_gravity ์์ฑ : ๋ถ๋ชจ ๋ทฐ ์์์ ํด๋น ๋ทฐ์ ์ ๋ ฌ ๋ฐฉ์ ์ง์
| BOTTOM | ๋ถ๋ชจ ๋ทฐ์์ ์๋์ชฝ์ ์์น์ํด |
| CENTER | ๋ถ๋ชจ ๋ทฐ์ ์ค์์ ์์น์ํด |
| CENTER_HORIZONTAL | ๋ถ๋ชจ ๋ทฐ์ ์ํ๊ธฐ์ค ์ค์์ ์์น์ํด |
| CENTER_VERTICAL | ๋ถ๋ชจ ๋ทฐ์ ์์ง๊ธฐ์ค ์ค์๋ฐ ์์น์ํด |
| END | ๋ถ๋ชจ ๋ทฐ์์ ํ ์คํธ ๋ฐฉํฅ์ ๋(ํ๊ธ, ์์ด๋ ์ค๋ฅธ์ชฝ)์ ์์น์ํด |
| LEFT | ๋ถ๋ชจ ๋ทฐ์์ ์ผ์ชฝ์ ์์น์ํด |
| RIGHT | ๋ถ๋ชจ ๋ทฐ์์ ์ค๋ฅธ์ชฝ์ ์์น์ํด |
| TOP | ๋ถ๋ชจ ๋ทฐ์์ ์์ชฝ์ ์์น์ํด |

<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="R | T"
android:gravity="right|top"
android:layout_gravity="right"/>
| ๊ฒ(๋ด์ฉ๋ฌผ ์์น) : gravity, ์(๋ถ๋ชจ ๋ทฐ): layout_gravity |
left | center_horizontal | right |
| top | left | center_horizontal | right |
| center_vertical | center_vertical | center ( gravity : x ) | center_vertical | right |
| bottom | bottom | center_horizontal | bottom | right | bottom |
//์ด ๋จผ์ , ๊ทธ ๋ค ํ (ex. left|top)
@@@ frame ์๋๋ ์ด๋ป๊ฒ ๋๋์ง ํ์ธ @@@
4. ์คํ์ผ ๋ฐ ํ ๋ง
1) ์คํ์ผ : view ๋๋ ์ฐฝ์ ๋ชจ์๊ณผ ํ์์ ์ง์ ํ๋ ์์ฑ ๋ชจ์ (๋์ด, ํจ๋ฉ, ๊ธ๊ผด ์์, ํฌ๊ธฐ, ๋ฐฐ๊ฒฝ์ ๋ฑ ์ง์ )
- ๋ ์ด์์์ ์ง์ ํ๋ xml๊ณผ ๋ณ๊ฐ์ธ xml ๋ฆฌ์์ค์ ์ ์๋จ
- ์๋๋ก์ด๋์ ์คํ์ผ์ ์น ๋์์ธ์ cascading ์คํ์ผ ์ํธ์ ์ ์ฌํจ -> ์ฝํ ์ธ ์ ๋์์ธ์ ๊ตฌ๋ถ ๊ฐ๋ฅ
res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RedTextView" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width"> wrap_content</item>
<item name="android:layout_height"> wrap_content</item>
<item name="android:textColor">#FF0000</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">24sp</item>
</style>
</resources>
@@@@
2) ํ ๋ง : ๊ฐ๋ณ View๊ฐ ์๋๋ผ ์ ์ฒด Activity ๋๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ์ฉ๋๋ ์คํ์ผ
- ์คํ์ผ์ด ํ
๋ง๋ก ์ ์ฉ๋ ๊ฒฝ์ฐ ์กํฐ๋นํฐ ๋๋ ์ดํ๋ฆฌ์ผ์ด์
์ ํฌํจ๋ ๋ชจ๋ ๋ทฐ๊ฐ ์์ ์ด ์ง์ํ๋ ๊ฐ ์คํ์ผ ์์ฑ์ ์ ์ฉํจ
(ex. ์กํฐ๋นํฐ์ ํ
๋ง์ ๋์ผํ CodeFont ์คํ์ผ์ ์ ์ฉํ ์ ์์ผ๋ฉฐ, ๊ทธ๋ฌ๋ฉด ํด๋น ์กํฐ๋นํฐ์ ํฌํจ๋ ๋ชจ๋ ํ
์คํธ์ ๋
น์์ ๊ณ ์ ํญ ๊ธ๊ผด์ด ์ ์ฉ๋จ)
<Button
style="@style/RedTextView"
android:text="L | T"
android:gravity="left|top"
android:layout_gravity="left"/>
@@์คํ์ผ์ด๋ ํ ๋ง๋ ๋ณ๊ฐ๊ฐ ์๋๋ผ ํ๋ฒ์ ์ฐ๋ ๊ฑฐ? style="@style/์ด์ฉ๊ตฌ " ์ด๋ ๊ฒ ๋ฃ๋ ๊ฒ ํ ๋ง์ธ๊ฐ? @@
์ค์ต
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp" //0์ผ๋ก ํด์ผ ํจ
android:layout_weight="1"
android:orientation="vertical" //๊ฒฐ๊ตญ ์ธ๋ก๋๊น
android:background="@color/black">
<Button
android:id="@+id/btn11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON1"/>
<Button
android:id="@+id/btn12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON2"
android:layout_gravity="center"/> //์์ง ์๋์นธ ๊ฐ์ด๋ฐ
<Button
android:id="@+id/btn13"
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:layout_margin="10dp" //ํ
๋๋ฆฌ ๋ง์ง์ผ๋ก ์ฒ๋ฆฌ. ํ
๋๋ฆฌ ์ ๋ฃ์ผ๋ ค๋ฉด
android:background="@android:color/holo_green_light"> //์ฒซ(๋ถ๋ชจ?) LinearLayout์์ background ์ ๋ฐ๊พธ๊ธฐ
<Button
android:id="@+id/btn21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/btn22" //๊ธฐ์ค ๋๊ณ ์. ๋ง์ง ๋๊ฑฐ๋ฉด layout_marginRight="20dp"
android:text="BUTTON4"/>
<Button
android:id="@+id/btn22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentRight="true" //์ฐ์ธก์ผ๋ก ๋ถ์
android:text="BUTTON5"/>
<Button
android:id="@+id/btn23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" //?? ์ด๊ฑด๋ญ์ง
android:layout_marginLeft="10dp" //์์ด๋ 10 ๋์
android:layout_below="@id/btn21" //๋ฐ
android:text="BUTTON6"/>
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_purple"
android:oriention="vertical">
<Button
android:id="@+id/btn31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON7"
app:layout_constraintBottom_toBottomOf="parent" //์ค์์ผ๋ก ๋ฐฐ์น
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="@+id/btn32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" //์ค๊ฐ ์์น
android:text="BUTTON8"
android:layout_marginLeft="20dp"
app:layout_constraintStart_toEndOf="@id/btn31" //์์์ด 7๋ฒ์ ๋
app:layout_constraintBottom_toBottomOf="@id/btn31"
app:layout_constraintTop_toTopOf="@id/btn31"/>
<Button
android:id="@+id/btn33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="BUTTON9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn31"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>'Android Studio' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Android ์ฑ๊ฐ๋ฐ ์ ๋ฌธ] Intent (# ์ถ๊ฐํ๊ธฐ) (0) | 2024.03.20 |
|---|---|
| [Android ์ฑ๊ฐ๋ฐ ์ ๋ฌธ] ์กํฐ๋นํฐ (# ์ถ๊ฐํ๊ธฐ) (0) | 2024.03.20 |
| [Android ์ฑ๊ฐ๋ฐ ์ ๋ฌธ] ๋ ์ด์์ (# ์ถ๊ฐํ๊ธฐ) (0) | 2024.03.19 |
| [Android ์ฑ๊ฐ๋ฐ ์ ๋ฌธ] ์์ ฏ (# ์ถ๊ฐํ๊ธฐ) (0) | 2024.03.18 |
| [Android ์ฑ๊ฐ๋ฐ ์ ๋ฌธ] ์๋๋ก์ด๋ UI ๊ธฐ๋ณธ (@ ์ถ๊ฐํ๊ธฐ) (0) | 2024.03.18 |