프로그래밍 언어/안드로이드

안드로이드 xml 레이아웃 겹치기 RelativeLayout 중첩

공포이야기 2016. 12. 7.
728x90

안드로이드 xml 레이아웃 겹치기에 관한 포스팅 입니다 RelativeLayout 으로 레이아웃 겹치기를 해보겠습니다

여러개의 레이아웃을 겹치기 할수 있지만 3개만 해보겠습니다

시작해 볼까요? 안드로이드 스튜디오를 켭니다~

LinearLayout을 horizontal로 한개 만들고 Layout 메뉴에서 RelativeLayout을 마우스로 드래그 클릭해서 LinearLayout 바로 밑에 추가를 해줍니다


이젠 RelativeLayout 레이아웃 안에 3개의 레이아웃을 추가해보겠습니다

방금했던 방법으로 레이아웃 드래그 해서 LinearLayout을 추가 해줍니다 크기는 android:layout_height="200dp"으로 맞추고 레이아웃 구별을 위해서 android:background="#FF0000"을 추가했습니다 이렇게 레이아웃 1개가 추가 되었습니다



두번째 레이아웃을 만들어보겠습니다

역시나 같은 방법으로 레이아웃에서 드래그해서 LinearLayout을 추가해줍니다 android:orientation="vertical 속성으로 해주었습니다 가로만 android:layout_width="200dp"로 설정해주었습니다



마지막 레이아웃을 만들어보겠습니다

같은 방법으로 하시면 되고요 LinearLayout > android:orientation="vertical 속성이고요 가로 역시 200dp로 똑같이 설정해주었습니다



이렇게 해서 레이아웃 겹치기를 해보았습니다

LinearLayout 속성은 horizontal, vertical은 본인이 배치하는 버튼이나 이미지 배치를 원하는 속성으로 해주시면 됩니다

가로로 배치 할려면 horizontal을 해주시면 되고요 세로로 배치 할려면 vertical 속성으로 바뀌주시면 됩니다




layout_width 이나 layout_height 레이아웃 크기는 본인 임의대로 지정하시면 됩니다


지금까지 만들 레이아웃입니다 직접 붙여넣기 해보시고 해보시면 이해가 가실겁니다


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
32
33
34
35
36
37
38
39
40
41
<?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"
    android:orientation="horizontal"
    tools:context="com.example.top.test.MainActivity">
 
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
        <LinearLayout
            android:background="#FF0000"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/linearLayout2">
        </LinearLayout>
 
        <LinearLayout
            android:background="#0054FF"
            android:orientation="vertical"
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:layout_below="@+id/linearLayout2"
            android:id="@+id/linearLayout">
        </LinearLayout>
 
        <LinearLayout
            android:background="#9FC93C"
            android:orientation="vertical"
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:layout_below="@+id/linearLayout2"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout">
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>
 
cs


728x90
반응형

댓글

💲 추천 글