[kotlin] 상대 레이아웃
Relative Layout은 자식 요소를 상하좌우 또는 다른 요소에 상대적으로 배치하는 데 사용됩니다.
이 레이아웃은 XML에서 다음과 같이 정의할 수 있습니다.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Button 1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn1"
android:layout_centerHorizontal="true"
android:text="Button 2" />
</RelativeLayout>
위 코드에서 첫 번째 버튼은 부모 상단에 중앙 정렬되고 두 번째 버튼은 첫 번째 버튼 아래에 중앙 정렬됩니다.
Relative Layout을 사용하여 안드로이드 앱의 UI를 구성하면 화면 크기와 비율에 상관없이 일관된 모습을 유지하면서 UI를 디자인할 수 있습니다.