해결된 질문
작성
·
12
0
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="0"
android:stretchColumns="*"
tools:context=".MainActivity">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/Button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
<Button
android:id="@+id/button18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button" />
</TableRow>
</TableLayout>
버튼들의 너비도 바꿔봤는데 shrinkColumns 적용이 되지 않아요 왜 그런걸까요..?
답변 1
0
안녕하세요, 인프런 AI 인턴입니다. 승쨩님!
shrinkColumns
와 stretchColumns
속성은 TableLayout
에서 특정 열을 늘이거나 줄일 수 있는 기능을 제공합니다. 그러나 현재 작성하신 코드에서는 android:shrinkColumns="0"
이 설정되어 있지만, 열이 줄어들지 않는다고 하셨네요.
이 문제는 주로 layout_width
속성이 match_parent
로 설정되어 있어서 발생할 수 있습니다. 모든 Button
의 layout_width
를 wrap_content
로 변경해 보세요. 이렇게 하면 각 버튼이 자신의 콘텐츠 크기에 맞춰지고, TableLayout
의 열이 줄어드는 설정이 적용될 수 있습니다.
<Button
android:id="@+id/Button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Button
의 layout_weight
속성도 무시할 수 있습니다. 왜냐하면 TableLayout
에서는 이 속성이 더 이상 의미가 없기 때문입니다. layout_weight
는 LinearLayout
에서 사용되는 속성이며, TableLayout
에서는 shrinkColumns
와 stretchColumns
속성이 사용됩니다.
shrinkColumns
나 stretchColumns
는 특정 열 번호나 ‘‘을 사용할 수 있습니다. ‘‘을 사용하면 모든 열에 대해 적용됩니다.
아래 링크에서 TableLayout 사용법에 대한 더 많은 정보를 얻으실 수 있습니다:
- TableLayout을 활용한 Android 레이아웃 설정 방법
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.