7-4 GridLayout

StrayCat·2022년 10월 5일
0

GridLayout

행과 열로 구성된 테이블 화면을 만드는 레이아웃 클래스이다.

<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:columnCount="3">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A"
        android:layout_gravity="fill_horizontal"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="C"
        android:layout_row="1"
        android:layout_column="1"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="D"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EFGHIJKLMNOPQRSTUVWXYZ"
         />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RIGHT"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_gravity="right" />

</GridLayout>
  • orientation 속성을 통해 방향을 결정한다.
    • "vertical" : 세로 배치
      • rowCount 속성값으로 줄바꿈
    • "horizontal" : 가로 배치
      • columnCount 속성값으로 줄바꿈
  • 특정 좌표에 배치할 수 있다.
    • layout_row : 세로 인덱스
    • layout_column : 가로 인덱스
  • layout_gravity 속성을 통해 해당 칸 내의 뷰 배치를 변경 할 수 있다.
    • "fill_horizontal" : 인덱스 여백 채우기
    • "right" : 해당 칸의 오른쪽 배치
  • 병합기능을 사용할 수 있다.
    • layout_columnSpan : 가로 열 병합
    • layout_rowSpan : 세로 열 병합

  • 테이블의 또다른 레이아웃 클래스로 TableLayout을 사용할 수 있다.

(XML 레이아웃 미리보기)

0개의 댓글