안드로이드 테이블 레이아웃(Android TableLayout)
ㅁ 표의 형식으로 차일드 뷰를 배치하는 레이아웃
ㅁ TableLayout은 TableRow로 구성되고 TableRow 하나가 표의 한 개 행을 의미한다.
ㅁ TableRow 안에는 여러 열이 배치되고 하나의 열은 셀이라고 한다.
(셀에는 하나의 차일드 뷰가 들어감)
ㅁ layout_height 기본속성은 wrap_content / layout_width은 match_parent
ㅁ 열의 폭은 같은 열에 있는 셀 중에서 가장 넓은 폭의 셀 기준으로 결정이 된다.
예제)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | <?xml version="1.0" encoding="utf-8"?> <TableLayout 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="vertical" tools:context=".MainActivity"> <TableRow> <TextView android:text="mon" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="tue" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="wed" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="thu" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="fri" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> </TableRow> <TableRow> <TextView android:text="11" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="12" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="13" android:padding="10dip" android:textStyle="bold" android:textSize="20" android:textColor="#ff0000" /> <TextView android:text="14" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="15" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> </TableRow> </TableLayout> | cs |
ㅁ shrinkColumns, stretchColumns 속성의 변경
- 특정 열의 축소/확장 기능 지정 가능
- 부모 view의 사용가능한 폭까지 가능
- 지정하고 싶은 열에 대해 comma( ' , ') 를 지정한다.
- setShrinkAllColumns(boolean) , setStretchAllColumns(boolean) 를 사용
테이블 레이아웃 부분에 아래 코드를 넣어주면 강제로 컬럼의 간격을 늘릴 수 있다.
1 | android:stretchColumns="1,2" | cs |
ㅁ 레이아웃 중첩
- 레이아웃은 view의 컨테이너이므로 viewGroup과 위젯을 레이아웃에 중첩 배치 가능
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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="vertical" android:stretchColumns="1,2" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20" android:textStyle="bold" android:text="I am first layout" /> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFF000"> <TableRow> <TextView android:text="mon" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="tue" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="wed" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="thu" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="fri" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> </TableRow> <TableRow> <TextView android:text="11" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="12" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="13" android:padding="10dip" android:textStyle="bold" android:textSize="20" android:textColor="#ff0000" /> <TextView android:text="14" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> <TextView android:text="15" android:padding="10dip" android:textStyle="bold" android:textSize="20" /> </TableRow> </TableLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am Third Layout" android:textSize="30" /> </RelativeLayout> </LinearLayout> | cs |
ㅁ 엘리먼트 속성 변경
- FrameLayout 레이아웃의 visibility 속성을 실행 시간에 바꾼다.
- how? 1. orientation을 사용한다. public void LinearLayout.setOrientation (int orientation)
- how? 2. gravity를 사용한다. public void TextView.setGravity (int gravity)
'문돌이의 IT > 안드로이드' 카테고리의 다른 글
안드로이드 입력이벤트 처리 (0) | 2018.06.22 |
---|---|
안드로이드 이벤트처리 (0) | 2018.06.21 |
방통대 모바일앱프로그래밍 강의자료 요약정리(1~6강) (0) | 2018.06.16 |
방통대 모바일앱프로그래밍 출석대체시험 기출문제풀이(3) (0) | 2018.06.15 |
방통대 모바일앱프로그래밍 출석대체시험 기출문제풀이(2) (0) | 2018.06.14 |