Xamarin.Android RelativeLayout

RelativeLayoutViewGroup 자식이 표시되는 항목입니다. View 상대 위치의 요소입니다. 위치 View 는 형제 요소(예: 지정된 요소의 왼쪽 또는 아래)에 상대적인 위치 또는 RelativeLayout 영역(예: 가운데 왼쪽의 아래쪽에 맞춰짐).

A RelativeLayout 는 중첩된 ViewGroup인터페이스를 제거할 수 있으므로 사용자 인터페이스를 디자인하기 위한 매우 강력한 유틸리티입니다. 중첩된 여러 항목을 사용하는 경우 LinearLayout 그룹을 단일 RelativeLayout로 바꿀 수 있습니다.

HelloRelativeLayout이라는 새 프로젝트를 시작합니다.

Resources/Layout/Main.axml 파일을 열고 다음을 삽입합니다.

<?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">
    <TextView
        android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Type here:"/>
    <EditText
        android:id="@+id/entry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/editbox_background"
        android:layout_below="@id/label"/>
    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dip"
        android:text="OK" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/ok"
        android:layout_alignTop="@id/ok"
        android:text="Cancel" />
</RelativeLayout>

각 특성(예: layout_below, layout_alignParentRightlayout_toLeftOf)을 android:layout_* 확인합니다. 사용 하는 RelativeLayout경우 이러한 특성을 사용 하 여 각 View위치를 지정 하는 방법을 설명할 수 있습니다. 이러한 각 특성은 서로 다른 종류의 상대 위치를 정의합니다. 일부 특성은 형제 View 의 리소스 ID를 사용하여 고유한 상대 위치를 정의합니다. 예를 들어 마지막 Button 은 ID ok (이전Button)로 식별된 왼쪽 및 맨 위에 View 정렬되도록 정의됩니다.

사용 가능한 모든 레이아웃 특성은 .에 정의되어 있습니다 RelativeLayout.LayoutParams.

에서 이 레이아웃을 로드해야 합니다. OnCreate() 메서드:

protected override void OnCreate (Bundle savedInstanceState)
{
    base.OnCreate (savedInstanceState);
    SetContentView (Resource.Layout.Main);
}

이 메서드는 리소스 ID Resource.Layout.Main 로 지정된 레이아웃 파일을 Activity로드합니다. 리소스/레이아웃/Main.axml 레이아웃 파일을 참조합니다.SetContentView(int)

애플리케이션을 실행합니다. 다음과 같은 레이아웃이 표시됩니다.

Screenshot of a relative layout with a TextView, EditText, and two buttons

리소스

이 페이지의 일부는 Android 오픈 소스 프로젝트에서 만들고 공유하고 Creative Commons 2.5 특성 라이선스에 설명된 용어에 따라 사용되는 작업을 기반으로 하는 수정 사항입니다.