마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

레이아웃 사이즈 고정하는 방법이 있나요?

0 추천

안녕하세요.

레이아웃 관련된 내용인데요.

화면에 LinearLayout (Horizontal) 하나를 올려놓고, 그 안에 두 개의 LinearLayout을 넣었습니다.

안쪽의 LinearLayout은 모두 layout:weight = 1이구요.

그런데 문제는 안쪽의 LinearLayout 하나에 TextView 같은걸 넣게되면 사이즈가 바뀌네요.

안쪽에 무엇을 넣든간에 처음의 layout:weight = 1 비율이 고정되었으면 좋겠는데요.

어떻게 설정해야 하나요?

///////

질문했다가 weightSum = 1 해주어서 해결된 듯 싶었으나..

확인해보니 사이즈가 다르네요.. ㅠㅠ

아래 이미지를 보면 두 개의 LinearLayout이 있는데 layout_weight = 1 로 설정되어 있습니다.

그리고 바깥쪽 레이아웃에 weightSum = 1 해주었는데요.

사실 오른쪽이 왼쪽보다 조금 더 가로 길이가 깁니다.

5:5 비율로 고정하는 방법이 궁금합니다.

케이엔비 (660 포인트) 님이 2016년 1월 12일 질문

3개의 답변

0 추천
 
채택된 답변
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="1">

<View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5"/>

<View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5"/>

</LInearLayout>

음.. 실행 해보진 않아서 ^^;  xml이 따로 올라온건 없기에 한번 적어봅니다...
귀찮근 (2,960 포인트) 님이 2016년 1월 12일 답변
케이엔비님이 2016년 1월 12일 채택됨
감사합니다. 이제 감 잡았네요.
0 추천

소스가 없어서 확실히 어떻게 하신지는 모르겠지만,

안에 들어가는 LinearLayout 2개의 width는 어떻게 하신건가요? 0dp나 match_parent로 하시고 weight 1을 주신건가요?

리니어안에 서브뷰들은 어떻게 하셨는지 구체적인걸 모르겠네요.

일단 2개의 리니어의 넓이를 꽉 채우시고 weight=1 을 해야 5:5비율이 적용됩니다.

캬옹이 (37,920 포인트) 님이 2016년 1월 12일 답변
안쪽의 두 개 width는 wrap_content 으로 되어 있습니다. layout:weight만 1로 하여 5:5로 나누었다가 안에 이미지도 넣고 텍스트도 넣고 했는데 비율이 틀어졌어요.
해당 부분만 복사해왔습니다.
아래처럼 되어 있어요.
<LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.05"
            android:weightSum="1">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="5dp"
                android:background="#00a9d9"
                android:gravity="center_vertical">

                <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:id="@+id/imageView6"
                    android:src="@drawable/icon_value"
                    android:layout_marginLeft="10dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Max value"
                    android:id="@+id/tvDetailMaxValue"
                    android:layout_marginLeft="10dp"
                    android:textIsSelectable="false"
                    android:textColor="#ffffff"
                    android:textSize="14dp"/>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#ffffff"
                    android:layout_marginTop="13dp"
                    android:layout_marginBottom="13dp"
                    android:layout_marginLeft="10dp">
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="100"
                    android:id="@+id/textView10"
                    android:layout_marginLeft="5dp"
                    android:textIsSelectable="false"
                    android:textColor="#ffffff"
                    android:textSize="14dp"
                    android:layout_marginRight="10dp"/>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="8dp"
                android:layout_marginLeft="3dp"
                android:layout_marginTop="5dp"
                android:background="#00a9d9"
                android:gravity="center_vertical">

                <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:id="@+id/imageView7"
                    android:src="@drawable/icon_time"
                    android:layout_marginLeft="10dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Max time"
                    android:id="@+id/tvDetailMaxTime"
                    android:layout_marginLeft="10dp"
                    android:textIsSelectable="false"
                    android:textColor="#ffffff"
                    android:textSize="14dp"/>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#ffffff"
                    android:layout_marginTop="13dp"
                    android:layout_marginBottom="13dp"
                    android:layout_marginLeft="10dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="12:15:38"
                    android:id="@+id/textView12"
                    android:textIsSelectable="false"
                    android:textColor="#ffffff"
                    android:textSize="14dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="5dp"/>
            </LinearLayout>
        </LinearLayout>
음.. 어쩐지 그럴거 같았어요..
wrap_content를 하면 weight가 의미가 없어집니다.
넓이가 유동적으로 변할테고 그 변한 상태에서 weight가 먹힐테니 두개의 길이가 다르면 보여지는게 달라질수 밖에없습니다..
0 추천
파란색 두개 리니어가 반반씩 잡혔으면 좋겠다고 하셨는데..

두개의 리니어 안에 텍스트뷰를 넣게되면 텍스트 뷰의 텍스트에 따라 비율이 틀어질거 같은데요.

 

최대 길이를 생각하고 텍스트뷰의 폰트 사이즈를 낮춰서 한번 테스트 해보세영
치솟음 (3,710 포인트) 님이 2016년 1월 12일 답변
...