테이블 레이아웃에 대해 정리해보겠다. 쉽게 5가지를 기억하면 된다.
1.tableLayout 안에 tableRow를 통해 행의 수를 조절할 수 있다
2. 행 안에 열의 수는 TableRow안의 위젯수로 나타낸다.
3. layout_span은 열을 합쳐서 표시한다는 의미이다. 만약 2인 값을 가지면 셀2개를 합치게 된다.
4. layout_column은 지정된 열에 현재 위젯을 표시한다. 만약 2인 값을 가지면 셀 2개정도 띄워진 뒤, 셀이 위치한다.
5. stretchColumns는 테이블 레이아웃에 넣은 속성으로 만약 *를 넣으면 셀의 크기는 전체화면이 꽉 차는 모두 같은 크기로 확장한다.(꼭 필요할 때만 넣기!)
xml 코드
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text = "1" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text = "2" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text = "3" />
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_column="2"
android:text = "4" />
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_span="3"
android:text = "5" />
</TableRow>
</TableLayout>
avd로 실행하고 싶다면, 꼭 코틀린 코드에 setContent를 잊지말것!(relatvelayout에 해당 정보가 담겨 있으므로 참고!)
실행화면
계산기와 같은 프로그램을 사용할 때, 사용하면 괜찮을 것 같다!
'안드로이드 프로그래밍📱 > XML 📃 코드 정리' 카테고리의 다른 글
[AndroidStudio] ConstraintLayout 복습 (0) | 2025.02.24 |
---|---|
[AndroidStudio] RelativeLayout 복습 (0) | 2025.02.19 |