별의 공부 블로그 🧑🏻‍💻
728x90
728x170
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<RelativeLayout 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:padding="10dp"
    android:background="@drawable/login_background" 
    >
    
    <TextView 
        android:id="@+id/titleLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:text="식당 찾기 도우미"
        android:textColor="#ffffffff"
        android:textStyle="bold"
        android:textSize="24dp"
        />
    
    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:padding="10dp"
        android:background="#aaffffff"
        >
        <TextView 
            android:id="@+id/usernameLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="4dp"
            android:text="Username : "
            android:textColor="#ff222222"
            android:textSize="18dp"
            />
        <EditText 
            android:id="@+id/usernameEntry"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/usernameLabel" 
            android:layout_alignBaseline="@id/usernameLabel"
            android:layout_marginLeft="4dp"
            />
        <TextView 
            android:id="@+id/passwordLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="16dp"
            android:layout_below="@id/usernameLabel"
            android:text="Password  : "
            android:textColor="#ff222222"
            android:textSize="18dp"
            />
        <EditText 
            android:id="@+id/passwordEntry"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_toRightOf="@id/passwordLabel" 
            android:layout_alignBaseline="@id/passwordLabel"
            android:inputType="textPassword"
            />    
        <Button 
            android:id="@+id/loginBtn"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/passwordLabel"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="16dp"
            android:text="Login" 
            android:drawableLeft="@drawable/ok_btn"
            android:drawablePadding="2dp"
            />
        <Button 
            android:id="@+id/exitBtn"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/passwordLabel"
            android:layout_alignParentRight="true"
            android:layout_marginRight="20dp"
            android:layout_marginTop="16dp"
            android:text="Exit" 
            android:drawableLeft="@drawable/cancel_btn"
            android:drawablePadding="2dp"
            />
    </RelativeLayout>
    
</RelativeLayout>
 
cs

 

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
<RelativeLayout 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"
    >
    
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:text="전체영역"
        android:textColor="#ff000000"
        android:textSize="24dp"
        android:gravity="center"
        android:background="#ff00ffff"
        />
    <Button 
        android:id="@+id/bottomButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="하단버튼"
        android:textColor="#ff000000"
        android:textSize="24dp"
        />
    
</RelativeLayout>
 
cs

 

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
<RelativeLayout 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"
    >
    
    <Button 
        android:id="@+id/topButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="상단버튼"
        android:textColor="#ff000000"
        android:textSize="24dp"
        />
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/topButton"
        android:layout_above="@+id/bottomButton"
        android:text="전체영역"
        android:textColor="#ff000000"
        android:textSize="24dp"
        android:gravity="center"
        android:background="#ff00ffff"
        />
    <Button 
        android:id="@+id/bottomButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="하단버튼"
        android:textColor="#ff000000"
        android:textSize="24dp"
        />
    
</RelativeLayout>
 
cs

 

*상대 레이아웃에서 부모 컨테이너와의 상대적 위치를 이용하는 속성

 속성

설명 

 layout_alignParentTop

 부모 컨테이너의 위쪽과 뷰의 위쪽을 맞춤

 layout_alignParentBottom

 부모 컨테이너의 아래쪽과 뷰의 아래쪽을 맞춤

 layout_alignParentLeft

 부모 컨테이너의 왼쪽 끝과 뷰의 왼쪽 끝을 맞춤

 layout_alignParentRight

 부모 컨테이너의 오른쪽 끝과 뷰의 오른쪽 끝을 맞춤

 layout_centerHorizontal

 부모 컨테이너의 수평 방향 중앙에 배치함

 layout_centerVertical

 부모 컨테이너의 수직 방향 중앙에 배치함

 layout_centerInParent

 부모 컨테이너의 수평과 수직 방향 중앙에 배치함

 

*상대 레이아웃에서 다른 뷰와의 상대적 위치를 이용하는 속성

속성 

설명 

layout_above

지정한 뷰의 위쪽에 배치함

layout_below

지정한 뷰의 아래쪽에 배치함

layout_toLeftOf

지정한 뷰의 왼쪽에 배치함

layout_toRightOf

지정한 뷰의 아래쪽에 배치함

layout_alignTop

지정한 뷰의 위쪽과 맞춤

layout_alignBottom

지정한 뷰의 아래쪽과 맞춤

layout_alignLeft

지정한 뷰의 왼쪽과 맞춤

layout_alignRight

지정한 뷰의 오른쪽과 맞춤

layout_alignBaseline

지정한 뷰와 내용물의 아래쪽 기준선(baseline)을 맞춤

 

출처 : Do It! 안드로이드 앱 프로그래밍 (정재곤 지음, 이지스퍼블리싱)

728x90
그리드형(광고전용)

'Programming > Android' 카테고리의 다른 글

기본 위젯들  (0) 2017.01.17
프레임 레이아웃과 뷰의 전환  (0) 2017.01.17
스크롤뷰  (0) 2017.01.17
테이블 레이아웃  (0) 2017.01.17
리니어 레이아웃  (0) 2017.01.16
레이아웃  (0) 2017.01.16
뷰와 뷰그룹  (0) 2017.01.16
인텐트와 데이터 전달  (0) 2017.01.08
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖