안드로이드 어플리케이션에서 가장 많이 활용하는 레이아웃이다. 상대적인 대상과의 위치를 지정할 수 있다.
예제는 간단하다. 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 |
'문돌이의 IT > 안드로이드' 카테고리의 다른 글
안드로이드스튜디오 어댑터뷰어(adapter viewer) ListView GridView Spinner (0) | 2016.05.27 |
---|---|
안드로이드 LinearLayout 예제 (0) | 2016.05.25 |
안드로이드 RelativeLayout 예제(1) (0) | 2016.05.22 |
베가 통합USB드라이버 다운로드 (0) | 2016.05.21 |
안드로이드스튜디오 설치 및 환경설정 (1) | 2016.05.20 |