본문 바로가기
모바일/Android View & Layout

[Android] RelativeLayout (Component 기준)

by drCode 2021. 4. 18.
728x90
반응형

핵심 ->> id를 정해놓아야함

 

android:layout_toRightOf="@id/기준잡는컴포넌트ID"

android:layout_toLeftOf="@id/기준잡는컴포넌트ID"

android:layout_below="@id/기준잡는컴포넌트ID"

android:layout_above="@id/기준잡는컴포넌트ID"

 

<?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/view1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#f23204"
        android:layout_centerInParent="true" />

    <TextView
        android:id="@+id/view2"
        android:layout_toRightOf="@id/view1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#FFEB3B"/>

    <TextView
        android:id="@+id/view3"
        android:layout_below="@id/view1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#3F51B5"/>

    <TextView
        android:id="@+id/view4"
        android:layout_above="@id/view1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#4CAF50"/>

    <TextView
        android:id="@+id/view5"
        android:layout_toLeftOf="@id/view1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#673AB7"/>


</RelativeLayout>
728x90
반응형

댓글