인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

승쨩님의 프로필 이미지
승쨩

작성한 질문수

윤재성의 자바 기반 안드로이드 앱개발 Part 1 - UI Programming

12강 TableLayout

12강에서 shrinkColumns 의 설정이 되지 않아요

해결된 질문

작성

·

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 적용이 되지 않아요 왜 그런걸까요..?

 

image.png

 

 

 

답변 1

0

안녕하세요, 인프런 AI 인턴입니다. 승쨩님!

shrinkColumnsstretchColumns 속성은 TableLayout에서 특정 열을 늘이거나 줄일 수 있는 기능을 제공합니다. 그러나 현재 작성하신 코드에서는 android:shrinkColumns="0"이 설정되어 있지만, 열이 줄어들지 않는다고 하셨네요.

이 문제는 주로 layout_width 속성이 match_parent로 설정되어 있어서 발생할 수 있습니다. 모든 Buttonlayout_widthwrap_content로 변경해 보세요. 이렇게 하면 각 버튼이 자신의 콘텐츠 크기에 맞춰지고, TableLayout의 열이 줄어드는 설정이 적용될 수 있습니다.

  • 아래와 같이 변경해보시길 권장드립니다:
    
    <Button
      android:id="@+id/Button5"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Button" />
    

Buttonlayout_weight 속성도 무시할 수 있습니다. 왜냐하면 TableLayout에서는 이 속성이 더 이상 의미가 없기 때문입니다. layout_weightLinearLayout에서 사용되는 속성이며, TableLayout에서는 shrinkColumnsstretchColumns 속성이 사용됩니다.

shrinkColumnsstretchColumns는 특정 열 번호나 ‘‘을 사용할 수 있습니다. ‘‘을 사용하면 모든 열에 대해 적용됩니다.

아래 링크에서 TableLayout 사용법에 대한 더 많은 정보를 얻으실 수 있습니다:
- TableLayout을 활용한 Android 레이아웃 설정 방법

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

승쨩님의 프로필 이미지
승쨩

작성한 질문수

질문하기