๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Android

Android:: TableLayout ๊ณผ GridLayout์˜ ์ฐจ์ด์™€ ๊ณ„์‚ฐ๊ธฐ View ๋งŒ๋“ค๊ธฐ

by ๋„์บ๋ฆฌ๐Ÿฑ 2020. 7. 7.
๋ฐ˜์‘ํ˜•

1) Table Layout๊ณผ GridLayout ์ฐจ์ด

๊ทธ๋ฆฌ๋“œ๋Š” fill์ด๋ž‘ span ์ด์šฉํ•ด์„œ ์…€ ๋ณ‘ํ•ฉ ์ˆ˜ํ–‰ // row, column, ์ธ๋ฑ์Šค ์ ‘๊ทผ ํŒ”๋ ˆํŠธ์—์„œ ๋Œ์–ด ์“ฐ๊ธฐ ๊ฐ€๋Šฅ.

ํ…Œ์ด๋ธ”์€ weight๋ž‘ span ์ด์šฉํ•˜์—ฌ ์…€ ๋ณ‘ํ•ฉ ์ˆ˜ํ–‰ // <Tablerow>์˜ ๋ฐ˜๋ณต,๋ฐ์ดํ„ฐ ์–‘์ด ์ ์€ ๊ฒฝ์šฐ์— ์œ ์šฉ.

 

ํ…Œ์ด๋ธ” ๋ ˆ์ด์•„์›ƒ์€ ๋ชจ๋“ ํ–‰์ด ์ธ์Šคํ„ด์Šคํ™” (tablerow) ๋˜์–ด์•ผ ํ•˜๊ณ , ์žฌํ™œ์šฉ ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ํ‘œ์‹œํ•  ๋ฐ์ดํ„ฐ ์ ์€ ๊ฒฝ์šฐ ์œ ์šฉ.

 

๊ทธ๋ฆฌ๋“œ ๋ ˆ์ด์•„์›ƒ์€ ํ•ญ๋ชฉ์„ ๊ทธ๋ฆฌ๋“œ์— ๋ฐฐ์—ดํ•˜๋Š” ๋ฆฌ์ŠคํŠธ๋ทฐ์™€ ๊ฐ™๋‹ค. 

๊ทธ๋ฆฌ๋“œ ๋ ˆ์ด์•„์›ƒ์˜ ๋ชฉ์ ์€, ์–ด๋Œ‘ํ„ฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์‹œํ•˜๊ณ  ์‚ฌ์šฉ์ž๊ฐ€ ํ‘œ์‹œ๋œ ๊ฐ ํ•ญ๋ชฉ์„ ํƒ์ƒ‰ํ•˜๊ณ  ์„ ํƒํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

๋™์ผํ•œ UI์˜ ๊ฒฝ์šฐ GridLayout์€ ์ผ๋ฐ˜์ ์œผ๋กœ TableLayout๋ณด๋‹ค ๋น ๋ฅด๊ณ  ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ ๊ฒŒ ์†Œ์š”๋œ๋‹ค

 

 

2) TableLayout์œผ๋กœ ๋งŒ๋“  ๊ณ„์‚ฐ๊ธฐ Code & View

 weight ๊ฐ’์œผ๋กœ ์…€ ๋ณ‘ํ•ฉ ์ˆ˜ํ–‰. span ๊ฐ’๋„ ๊ฐ™์ด ํ™œ์šฉ.

 

<?xml version="1.0" encoding="utf-8"?>

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:gravity="center"
    android:layout_height="match_parent">

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <TextView
            android:id="@+id/textView"
            android:layout_weight="1"
            android:text="Num1 : "
            android:textSize="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="HardcodedText,SpUsage" />
        <EditText
            android:id="@+id/edNum1"
            android:layout_weight="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:layout_span="4"
            tools:ignore="Autofill,LabelFor" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <TextView
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:text="Num2 : "
            android:textSize="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="HardcodedText,SpUsage" />
        <EditText
            android:id="@+id/edNum2"
            android:layout_weight="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:layout_span="4"
            tools:ignore="Autofill,LabelFor" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <ImageButton
            android:id="@+id/imageButton"
            android:layout_weight="1"
            android:src="@drawable/ic_add_circle_black_24dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ContentDescription" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_weight="1"
            android:text="0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_weight="1"
            android:text="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_weight="1"
            android:text="8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="1"
            android:text="9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
        <Button
            android:layout_weight="2"
            android:layout_span="2"
            android:text="="
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ButtonStyle,HardcodedText" />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">

        <Button
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_weight="1"
            android:layout_span="2"
            android:text="@string/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_weight="1"
            android:layout_span="2"
            android:text="@string/subtract"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_weight="1"
            android:layout_span="2"
            android:text="@string/multiply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </TableRow>

    <TableRow
        android:layout_width ="match_parent"
        android:layout_height ="match_parent">
        <Button
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_weight="1"
            android:layout_span="2"
            android:text="@string/divide"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </TableRow>

    <TableRow>
        <EditText
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            android:layout_weight="1"
            android:layout_span="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            tools:ignore="Autofill,LabelFor" />
    </TableRow>


</TableLayout>

3)GridLayout์œผ๋กœ ๋งŒ๋“  ๊ณ„์‚ฐ๊ธฐ Code & View  fill ๊ณผ span ๊ฐ’์œผ๋กœ ๋ณ‘ํ•ฉ ๊ฐ™์ด ํ™œ์šฉ.

<?xml version="1.0" encoding="utf-8"?>

<GridLayout
    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"
    android:orientation="horizontal"
    android:columnCount="4"
    android:rowCount="11">

    <TextView

        android:id="@+id/textView25"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_marginLeft="10dp"

        android:text="num1 : "
        tools:ignore="HardcodedText,RtlHardcoded" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="0"
        android:layout_column="1"
        android:layout_columnSpan="3"
        android:layout_gravity="fill_horizontal"
        tools:ignore="Autofill,LabelFor,TextFields" />

    <TextView
        android:id="@+id/textView26"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_marginLeft="10dp"
        android:text="num2 : "
        tools:ignore="HardcodedText,RtlHardcoded" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="1"
        android:layout_column="1"
        android:layout_columnSpan="3"
        android:layout_gravity="fill_horizontal"
        tools:ignore="Autofill,LabelFor,TextFields"/>

    <ImageButton
        android:id="@+id/imageButton16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="2"
        android:layout_column="1"
        android:layout_gravity="fill_horizontal"
        android:layout_columnSpan="2"
        app:srcCompat="@drawable/ic_add_circle_black_24dp"
        tools:ignore="ContentDescription,VectorDrawableCompat" />

    <Button
        android:id="@+id/button5"
        android:layout_width="98dp"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="0"
        android:layout_gravity="fill_horizontal"
        android:text="0"
        tools:ignore="HardcodedText" />

    <Button
        android:id="@+id/button6"
        android:layout_width="105dp"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="1"
        android:layout_gravity="fill_horizontal"
        android:text="1"
        tools:ignore="HardcodedText" />

    <Button
        android:id="@+id/button7"
        android:layout_width="101dp"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="2"
        android:layout_gravity="fill_horizontal"
        android:text="2"
        tools:ignore="HardcodedText" />

    <Button
        android:id="@+id/button8"
        android:layout_width="117dp"
        android:layout_height="wrap_content"
        android:layout_row="3"
        android:layout_column="3"
        android:layout_gravity="fill_horizontal"
        android:text="3"
        tools:ignore="HardcodedText" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="4"
        android:layout_column="0"
        android:text="4"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="4"
        android:layout_column="1"
        android:text="5"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="4"
        android:layout_column="2"
        android:text="6"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="4"
        android:layout_column="3"
        android:text="7"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="5"
        android:layout_column="0"
        android:text="8"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="5"
        android:layout_column="1"
        android:text="9"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"
        />

    <Button
        android:id="@+id/button15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="5"
        android:layout_column="2"
        android:layout_columnSpan="2"
        android:text="@string/equals"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText"/>

    <Button
        android:id="@+id/button16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="6"
        android:layout_column="1"
        android:layout_columnSpan="2"
        android:text="@string/add"
        android:layout_gravity="fill_horizontal"/>

    <Button
        android:id="@+id/button17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="7"
        android:layout_column="1"
        android:text="@string/subtract"
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"/>

    <Button
        android:id="@+id/button18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="8"
        android:layout_column="1"
        android:text="@string/multiply"
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"/>

    <Button
        android:id="@+id/button19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_row="9"
        android:layout_column="1"
        android:text="@string/divide"
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"/>

    <TextView
        android:id="@+id/textView27"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_row="10"
        android:layout_column="1"
        android:text="RESULT"
        android:background="@color/colorBlue"
        android:layout_columnSpan="2"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:layout_gravity="fill_horizontal"
        tools:ignore="HardcodedText" />


</GridLayout>
๋ฐ˜์‘ํ˜•

'Android' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Android::LifeCycle ํ™œ์šฉํ•˜์—ฌ App๋งŒ๋“ค๊ธฐ  (0) 2020.07.21
Android::Awesome UI  (0) 2020.07.14
Android:: RelativeLayout ๊ณผ ConstraintLayout์˜ ์ฐจ์ด  (0) 2020.07.07
Android::Layout  (1) 2020.07.02
Android::Manifest  (1) 2020.07.01

๋Œ“๊ธ€