Archives
Recent Posts
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Today
Total
관리 메뉴

안드로이드 개발자의 창고

[28일차 Android] Space 본문

Computer/Android

[28일차 Android] Space

Wise-99 2023. 6. 10. 03:23

 

 

 

출처 : 안드로이드 앱스쿨 2기 윤재성 강사님 수업 PPT

 

 

 

📖 Space

  • Space는 Layout은 아니지만 Layout을 이용해 화면을 구성할 때 보조 수단으로 사용하는 View이다.
  • 화면을 구성할 때 여백이 필요할 경우 사용한다.

주요 속성

  • layout_width, layout_height를 통해 여백을 설정한다.

 

 

 

예제 코드

<?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"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="Button" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Space
            android:layout_width="50dp"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

    </LinearLayout>

    <Space
        android:layout_width="wrap_content"
        android:layout_height="50dp" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

코드 리뷰

  • button
    • layout_marginLeft="50dp"을 사용하여 왼쪽 여백을 표시한다.
  • button3
    • LinearLayout(horizontal)에서 Space를 사용한다.
    • Space를 layout_width="50dp"으로 설정하여 button3의 왼쪽 여백을 표시한다.
  • button4
    • LinearLayout(vertical)에서 Space를 사용한다.
    • Space를 layout_height="50dp"으로 설정하여 button4의 위쪽 여백을 표시한다.

 

 

 

결과