본문 바로가기
computing

20251002_android_5_layout속성

by greentworkshop 2025. 10. 2.

버튼의 위치 - layout_gravity, 버튼 텍스트의 위치 - gravity

//main01.xml

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

    <Button
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:background="#0000ff"
        android:text="button1"
        android:layout_gravity="center"
        android:gravity="right"
        ></Button>
    <Button
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:background="#0000ff"
        android:text="button1"
        android:layout_gravity="left"
        android:gravity="fill_vertical"
        ></Button>
    <Button
        android:layout_width="110dp"
        android:layout_height="110dp"
        android:background="#0000ff"
        android:text="button1"
        android:layout_gravity="right"
        android:gravity="bottom|right"
        ></Button>
	<!--두 가지 속성을 동시에 사용하기 위해서 | 파이프라인 기호 사용, 띄어쓰기는X-->
</LinearLayout>

레이아웃 구분 - linearlayout, 레이아웃 크기 균등하게 배분 - layout_weight

//main02.xml

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button1"
            ></Button>
        <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="button2"
           ></Button>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="#00ff00"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button3"
            ></Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button4"
            ></Button>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:background="#0000ff"
        android:layout_weight="1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button5"
            ></Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button6"
            ></Button>
    </LinearLayout>

</LinearLayout>

'computing' 카테고리의 다른 글

(Servlet, JSP), (MVC,MVCS), (MVVM, MVP)  (0) 2025.10.01
20250929_iOS5  (0) 2025.09.29
20250925_android4  (0) 2025.09.25
20250922_iOS4  (0) 2025.09.22
20250918_android3  (0) 2025.09.18