본문 바로가기

JAVA/안드로이드 프로그래밍

Android Studio를 활용한 안드로이드 프로그래밍 연습문제 237~238p 4,5,6번 문제

MainActivity.XML - 4번 문제

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2."
        android:orientation="horizontal"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            >
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#ff0"
            >
        </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#000000"
                >
            </LinearLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#0000FF"
                >
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#01DF3A"
                >
            </LinearLayout><LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FF0000"
            >
        </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:background="  #04B4AE"
        >
    </LinearLayout>
</LinearLayout>

 


MainActivity.XML - 5번 문제

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/baseBtn"
        android:layout_alignParentLeft="true"
        android:text="1번"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/baseBtn"
        android:layout_alignParentLeft="true"
        android:text="2번"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/baseBtn"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="-90dp"
        android:text="3번" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/baseBtn"
        android:text="4번"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/baseBtn"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="-90dp"
        android:text="5번" />
    />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/baseBtn"
        android:layout_alignParentRight="true"
        android:text="6번"

        />


</RelativeLayout>

 


MainActivity.XML - 6번 문제

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layBase"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="#A901DB"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/lay1"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:gravity="center"
        android:background="#4B088A"
        >
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:gravity="center"
            android:background="#FFFF00"
            >
            <LinearLayout
                android:id="@+id/lay3"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="#000000"
                >
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>


리니어 레이아웃과 리엑티브 레이아웃을 이용하여 연습문제를 풀어야합니다.