안드로이드 개발자의 창고
[28일차 Android] Space 본문
출처 : 안드로이드 앱스쿨 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의 위쪽 여백을 표시한다.
결과
'Computer > Android' 카테고리의 다른 글
[28일차 Android] Button (0) | 2023.06.10 |
---|---|
[28일차 Android] TextView (0) | 2023.06.10 |
[28일차 Android] Include Other Layout (0) | 2023.06.10 |
[27일차 Android] Layout(LinearLayout, RelativeLayout, ConstraintLayout) (0) | 2023.06.09 |
[27일차 Android] View Binding (0) | 2023.06.07 |