1. LinearLayout
가장 기본적으로 많이 사용하는 레이아웃.
레이아웃을 수평 수직으로 배치해줍니다.
아래의 소스의 밑줄친 소스를 보시면 orientation 속성을 통해 vertical 세로배치와 horizontal 가로배치로 해줄수 있다.
추가로 기초적인 속성을 살펴보면
layout_width, layout_height 속성값에는 꽉채워주는 "fill_parent", 필요한 만큰의 공간 차지 "wrap_content", 직접값을 "120px" 처럼 값을 지정해줄수 있다.
추가로 html 처럼 padding이라는 속성이 있어 자유롭게 레이아웃을 꾸며줄수 도 있다.
다음 예제는 linearlayout으로 가로배치와 세로배치를 살펴볼수 있다.
그리고 패딩값을 줌으로써 다음 LinearLayout에서 그 공간을 제외하고서 안에 bagroundColor가 채워진것을 보고서 fill_parent, wrap_content 를 살펴보면 된다.
레이아웃내의 요소들끼리 위치관계를 부여하고, 그 관계에 따라 화면을 구성.
속성값을 살펴보면..
다음 예제의 맨 밑줄에 속성들을 자세히 살펴보면 다음 RelativeLayout이 쓰이는 용도를 알 수 있다.
가장 기본적으로 많이 사용하는 레이아웃.
레이아웃을 수평 수직으로 배치해줍니다.
아래의 소스의 밑줄친 소스를 보시면 orientation 속성을 통해 vertical 세로배치와 horizontal 가로배치로 해줄수 있다.
추가로 기초적인 속성을 살펴보면
layout_width, layout_height 속성값에는 꽉채워주는 "fill_parent", 필요한 만큰의 공간 차지 "wrap_content", 직접값을 "120px" 처럼 값을 지정해줄수 있다.
추가로 html 처럼 padding이라는 속성이 있어 자유롭게 레이아웃을 꾸며줄수 도 있다.
다음 예제는 linearlayout으로 가로배치와 세로배치를 살펴볼수 있다.
그리고 패딩값을 줌으로써 다음 LinearLayout에서 그 공간을 제외하고서 안에 bagroundColor가 채워진것을 보고서 fill_parent, wrap_content 를 살펴보면 된다.
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:background="#ffffff"
-
android:paddingLeft = "20px"
-
android:paddingTop = "20px"
-
android:paddingRight = "20px"
-
android:paddingBottom = "20px"
-
>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="vertical" =========>세로배치
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:background="#ff0000"
-
>
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="vertical"
-
/>
-
<Button
-
android:text="버튼"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
/>
-
<EditText
-
android:text="EditText"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
/>
-
</LinearLayout>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="horizontal" ========>가로배치
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:background="#0000ff"
-
>
-
<TextView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="horizontal"
-
/>
-
<Button
-
android:text="버튼"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
/>
-
<EditText
-
android:text="EditText"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
/>
-
</LinearLayout>
레이아웃내의 요소들끼리 위치관계를 부여하고, 그 관계에 따라 화면을 구성.
속성값을 살펴보면..
속성 | 설명 |
layout_above | ~의 위에 배치한다. |
layout_below | ~의 아래에 배치한다. |
layout_toLeftOf | ~의 왼쪽에 배치한다. |
layout_toRightOf | ~의 오른쪽에 배치한다. |
layout_alignLeft | ~와 왼쪽 변을 맞춘다. |
layout_alignTop | ~와 위쪽 변을 맞춘다. |
layout_alignRight | ~와 오른쪽 변을 맞춘다. |
layout_alignBottom | ~와 아래쪽 변을 맞춘다. |
layout_alignParentLeft | true이면 부모와 왼쪽 변을 맞춘다. |
layout_alignParentTop | true이면 부모와 위쪽 변을 맞춘다. |
layout_alignParentRight | true이면 부모와 오른쪽 변을 맞춘다. |
layout_alignParentBottom | true이면 부모와 아래쪽 변을 맞춘다. |
layout_alignBaseline | ~와 베이스라인을 맞춘다. |
layout_alignWithParentIfMissing | layout_toLeftOf 등의 속성에 대해 앵커가 발견되지 않으면 부모를 앵커로 사용한다. |
layout_centerHorizontal | true이면 부모의 수평 중앙에 배치한다. |
layout_centerVertical | true이면 부모의 수직 중앙에 배치한다. |
layout_centerInParent | true이면 부모의 수평, 수직 중앙에 |
다음 예제의 맨 밑줄에 속성들을 자세히 살펴보면 다음 RelativeLayout이 쓰이는 용도를 알 수 있다.
-
<?xml version="1.0" encoding="utf-8"?>
-
<RelativeLayout
-
xmlns:android="http://schemas.android.com/apk/res/android"
-
android:layout_width="fill_parent"
-
android:layout_height="wrap_content"
-
android:background="#ffffff"
-
android:padding="5px"
-
>
-
<ImageView
-
android:id="@+id/picture"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_alignParentLeft="true"
-
android:layout_marginRight="5px"
-
android:src="@drawable/picman"
-
/>
-
<Button
-
android:id="@+id/btndel"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="Del"
-
android:textSize="6pt"
-
android:layout_below="@id/picture"
-
/>
-
<TextView
-
android:id="@+id/name"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="최찬호"
-
android:textColor="#000000"
-
android:textSize="12pt"
-
android:layout_alignParentTop="true"
-
android:layout_toRightOf="@id/picture"
-
/>
-
<TextView
-
android:id="@+id/call"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="010-3456-8146"
-
android:textColor="#0000ff"
-
android:textSize="6pt"
-
android:layout_alignParentRight="true"
-
android:layout_alignBaseline="@id/name"
-
/>
-
<TextView
-
android:id="@+id/description"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="이것저것 쓰면서 아무거나 에헤라디야 안녕하세요 저는 최찬호입니다. 친해지고 싶네요..ㅋㅋ 야호야호 써지나 한번 볼까"
-
android:textColor="#000000"
-
android:textSize="6pt"
-
android:layout_below="@id/name"
-
android:layout_alignLeft="@id/name"
-
/>
-
<?xml version="1.0" encoding="utf-8"?>
-
-
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="vertical"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
>
-
<TableRow
-
android:layout_weight = "1"
-
>
-
<EditText
-
android:id = "@+id/resultText"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:layout_weight = "1"
-
android:text=""
-
android:gravity="center_vertical|right"
-
android:background="#ffffff"
-
/>
-
</TableRow>
-
<TableRow
-
android:layout_weight = "1"
-
android:background="#ff0000"
-
>
-
<Button
-
android:id="@+id/num7"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="7"
-
android:layout_weight = "1"
-
-
/>
-
<Button
-
android:id="@+id/num8"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="8"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num9"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="9"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/divide"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="/"
-
android:layout_weight = "1"
-
/>
-
</TableRow>
-
<TableRow
-
android:layout_weight = "1"
-
android:background="#00ff00"
-
>
-
<Button
-
android:id="@+id/num4"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="4"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num5"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="5"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num6"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="6"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/multi"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="*"
-
android:layout_weight = "1"
-
/>
-
</TableRow>
-
<TableRow
-
android:layout_weight = "1"
-
android:background="#0000ff"
-
>
-
<Button
-
android:id="@+id/num1"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="1"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num2"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="2"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num3"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="3"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/minus"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="-"
-
android:layout_weight = "1"
-
/>
-
</TableRow>
-
<TableRow
-
android:layout_weight = "1"
-
android:background="#666666"
-
>
-
<Button
-
android:id="@+id/clear"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="c"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/num0"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="0"
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/result"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="="
-
android:layout_weight = "1"
-
/>
-
<Button
-
android:id="@+id/plus"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:text="+"
-
android:layout_weight = "1"
-
/>
-
</TableRow>