<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_weight="33"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼1">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼2">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:background="#00ff00"
android:layout_weight="33"
android:orientation="horizontal">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼3">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼4">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:background="#0000ff"
android:layout_weight="33"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼5">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="버튼6">
</Button>
</LinearLayout>
</LinearLayout>
layout_weight는 중복 레이아웃을 사용할 때 layout을 화면에 꽉차게 하고 싶을 때 사용된다. dp를 이용하지 않고 상대적인 비율 개념으로 들어가기 때문에 기기의 크기가 다르더라도 화면을 꽉차게 해서 출력해 줄 수 있다. 주의 할 점은 꼭 layout_height를 0으로 해줘야 한다는 것이다.
실행화면
'안드로이드 > 연습' 카테고리의 다른 글
[Android] xml RelativeLayout 2 (0) | 2021.08.11 |
---|---|
[Android] RelativeLayout 속성 (0) | 2021.08.11 |
[Android] 단순한 계산기 (0) | 2021.08.10 |
[Android] XML 텍스트 색깔 지정 및 위치 조정하기 (0) | 2021.08.10 |
[Android] 좀 그럴 듯한 앱 (0) | 2021.08.10 |