Programming/Android

안드로이드 프로그래밍 RelativeLayout 예제

fishersheep 2021. 8. 16. 17:57
반응형

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/basebtn"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="기준위젯"/>

    <Button
        android:id="@+id/btn1"
        android:layout_alignTop="@+id/basebtn"
        android:layout_toLeftOf="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1번"/>

    <Button
        android:id="@+id/btn2"
        android:layout_below="@+id/btn1"
        android:layout_toLeftOf="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2번"/>

    <Button
        android:layout_below="@+id/btn2"
        android:layout_toLeftOf="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3번"/>

    <Button
        android:layout_above="@+id/basebtn"
        android:layout_alignLeft="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4번"/>

    <Button
        android:layout_alignRight="@+id/basebtn"
        android:layout_below="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="5번"/>

    <Button
        android:layout_above="@+id/basebtn"
        android:layout_toRightOf="@+id/basebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="6번"/>

</RelativeLayout>

안드로이드프로그래밍 relativelayout

반응형