LinearLayout 사용법과 속성
레이아웃(Layout)의 종류 중 하나인 LinearLayout에 대해 더 자세히 알아 보겠습니다.
LinearLayout (리니어 레이아웃)
Linear(선의, 선형의)의 뜻처럼 가로나 세로 방향으로 나열 할 때 사용합니다. 뷰의 위치를 지정 하지 않아도 중첩되지 않고 자동으로 나열됩니다.
속성
orientation - horizontal, vertical 나열 방향을 정합니다.
weight - 가중치를 정합니다.
리니어 레이아웃에서 orientation으로 vertical(수직, 세로, 위에서 아래) 또는 horizontal(수평, 가로, 왼쪽에서 오른쪽)으로 지정 가능합니다. orientation속성을 쓰지 않으면 기본적으로 horizontal로 나열되게 되어있습니다.
weight로 뷰마다 레이아웃에서 차지하는 비율을 정할 수 있습니다. 텍스트뷰 4개의 weight를 1로 설정하면 레이아웃에서 비율이 1:1:1:1로 지정이되고 weight를 다르게 주면 각 수치에 맞게 레이아웃에 비율대로 차지합니다.
리니어 레이아웃 orientation속성을 horizontal에 텍스트뷰 weight을 1로 했을 시
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView1"
android:layout_weight="1"
android:background="#ff9966"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView2"
android:layout_weight="1"
android:background="#66ffcc"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView3"
android:layout_weight="1"
android:background="#99ff00"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView4"
android:layout_weight="1"
android:background="#cc00ff"
android:layout_margin="5dp"
/>
</LinearLayout>
리니어 레이아웃 orientation속성을 vertical에 텍스트뷰 weight을 1로 했을 시
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView1"
android:layout_weight="1"
android:background="#ff9966"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView2"
android:layout_weight="1"
android:background="#66ffcc"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView3"
android:layout_weight="1"
android:background="#99ff00"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView4"
android:layout_weight="1"
android:background="#cc00ff"
android:layout_margin="5dp"
/>
</LinearLayout>
더 자세한 리니어 레이아웃의 설명은 개발자 페이지에서 보실 수 있습니다.
선형 레이아웃 | Android 개발자 | Android Developers
선형 레이아웃 | Android 개발자 | Android Developers
LinearLayout은 세로 또는 가로의 단일 방향으로 모든 하위 요소를 정렬하는 뷰 그룹입니다. LinearLayout이 서로 스택된 상태에서 레이아웃 방향을 지정할 수 있기 때문에, 세로 목록에는 행 하나당 하
developer.android.com
레이아웃 속성모음 보러 가기
[안드로이드 앱 만들기 기초] Layout(레이아웃) 속성, 사용법 모음 (tistory.com)
[안드로이드 앱 만들기 기초] Layout(레이아웃) 속성, 사용법 모음
앞서 얘기한 레이아웃들의 속성을 모아 놓았습니다. 프로그램 제작 시 필요할때 꺼내 보는식으로 보면 좋을듯 합니다. 1. LinearLayout (리니어 레이아웃) 속성 orientation - horizontal, vertical 나열 방향
codenet.tistory.com
리니어레이아웃을 사용하여 로그인 화면 구현하기
[안드로이드 스튜디오 활용] Layout 예제, 레이아웃으로 UI 구현 - 1. 로그인 화면 만들기 (tistory.com)
[안드로이드 스튜디오 활용] Layout 예제, 레이아웃으로 UI 구현 - 1. 로그인 화면 만들기
Layout을 활용하여 만든 간단한 레이아웃 UI 예제입니다. 구현하려는 앱에 참고해보시기 바랍니다. 레이아웃을 사용 할 줄 안다면 누구나 쉽게 구현 할 수 있습니다. 1. 기획 기획이라고 거창하게
codenet.tistory.com
'앱 비지니스 > 안드로이드 스튜디오' 카테고리의 다른 글
[안드로이드 앱 만들기 기초] TableLayout(테이블 레이아웃) 사용법, 속성 (0) | 2021.02.02 |
---|---|
[안드로이드 앱 만들기 기초] RelativeLayout(렐러티브 레이아웃) 사용법, 속성 (0) | 2021.02.01 |
[안드로이드 앱 만들기 기초] View, 위젯의 종류와 속성 (0) | 2021.01.28 |
[안드로이드 앱 만들기 기초] Layout의 종류와 속성 (0) | 2021.01.27 |
[안드로이드 앱 만들기 기초] Layout 레이아웃 (0) | 2021.01.26 |
댓글