안드로이드 어플리케이션에서 가장 많이 활용하는 레이아웃이다. 상대적인 대상과의 위치를 지정할 수 있다


 예제는 간단하다. RelativeLayout 베이스에서 화면의 중간에 큰 버튼을 하나 두고 이 버튼과의 상대적인 간격을 둔 3개의 버튼을 생성하는 예제이다






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
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <Button
        android:id="@+id/center"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="센터버튼"
        android:layout_centerInParent="true"
        android:layout_above="@id/center"
        android:layout_alignRight="@id/center"/>
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="버튼A"
        android:layout_above="@id/center"
        android:layout_toRightOf="@id/center"/>
 
    <!--센터버튼을 기준으로 왼쪽 벽에 맞춰짐 -->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="버튼B"
        android:layout_below="@id/center"
        android:layout_alignLeft="@id/center"/>
 
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="버튼C"
        android:layout_toLeftOf="@id/center"
        android:layout_alignTop="@id/center"/>
 
</RelativeLayout>
 
 
cs


+ Recent posts