안드로이드 레이아웃 : 테이블 레이아웃(TableLayout)과 stretchColumn
필그램
·2017. 7. 25. 08:04
안드로이드를 개발하면서, 자주쓰게 되는 'TableLayout'을 알아보겠습니다.
TableLayout(테이블 레이아웃)은 아래 그림처럼 버튼이나 이미지를 테이블로 넣을때 사용합니다.
xml 코드는 아래와 같습니다.
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/button19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"android:text="Button"/>
이렇게 테이블 레이아웃 태그안에 TableRow를 넣고 그 안에 버튼을 넣습니다.
하지만, 이 경우 버튼이 왼쪽으로 치우치고, 오른쪽이 비어지게 되는데 이때 추가하는 것이 stretchColumns 입니다. stretchColums를 테이블 레이아웃 안에 넣으면 버튼이 꽉차게 입력됩니다.
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2">
stretchColums 뒤의 0,1,2는 0번째, 1번째, 2번째 버튼을 stretch(벌려라)라고 하는 것입니다. 이것을 그림으로 보면 아래와 같습니다.
만약 0과 1만 써준다면 첫번째와 두번째 버튼만 넓어지고, 세번째 버튼은 wrap_content의 크기 만큼만 차지하게 될 것입니다.
한번 테스트 해보면 되겠습니다.
'프로그래밍 > 모바일: iOS, Java, Android, Swift' 카테고리의 다른 글
안드로이드 레이아웃 인플레이션 ( LayoutInflater ) (0) | 2017.07.27 |
---|---|
안드로이드 - 라디오버튼 만들기 (0) | 2017.07.26 |
[JAVA] 추상클래스 (abstract) (0) | 2017.07.19 |
[Android] Change Images with button click (버튼클릭시 이미지 변경) (0) | 2017.07.17 |
[JAVA] 스택과 큐(Stacks and Queues) 알아보기(1) (0) | 2017.07.14 |