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

fragment를 사용하는데 레이아웃이 이상하게 잡힙니다. [closed]

0 추천

tabhost말고 fragment를 이용해서 상단에 버튼 네개를 배치하고,

버튼을눌러 각 페이지를 하단에 보여주는 식으로 구성했습니다.

메인 레이아웃 xml에서

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffffff"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="15dp"
            android:layout_weight="1.99"
            android:background="#ffffffff"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btn_1"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />

            <Button
                android:id="@+id/btn_2"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />

            <Button
                android:id="@+id/btn_3"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                 />
            
             <Button
                android:id="@+id/btn_4"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                 />
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="18.66"
            android:background="#FFC19E"
            android:orientation="vertical" />
        
     
        
    </LinearLayout>
    

</RelativeLayout>

 

이렇게 구성해서, 상단에 버튼, 아래엔 각 페이지를 띄워줄 프래그먼트 레이아웃으로 나눴습니다.

그리고, btn_1을 눌렀을 때 아랫쪽에 해당 레이아웃이 나오긴 하는데, 윗쪽의 버튼배치영역의 높이가 작아지면서

버튼이 찌그지네요 ㅠㅠ..

아래 소스는 btn_1을 눌렀을 때 프래그먼트에 보여줄 one.xml 입니다.

비율면에서 뭔가를 잘못건드린걸까요? 메인xml에서 이미 프래그먼트로 보여줄 영역을 나눠서

윗쪽 영역[버튼배치]은 간섭을 안받을거라 생각했는데 , 위의 영역 높이가 줄어듭니다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#dfdfdf">
        
      
        <Button 
            android:id="@+id/tool_01"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            />
         <Button 
            android:id="@+id/tool_02"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            />
     
    </LinearLayout>

    
     <LinearLayout 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#dfdfdf"/>
         
</LinearLayout>

 

질문을 종료한 이유: 리니어 레이아웃 weight을 수정했습니다^^
anci (19,950 포인트) 님이 2014년 12월 11일 질문
anci님이 2014년 12월 11일 closed

1개의 답변

0 추천
one.xml에서 background가 #dfdfdf인 LinearLayout의 height를 0px로 해야 할것 같은데요..^^

둘다 match_parent로 되어있어서 그러는것 아닌가요?
지미라 (4,330 포인트) 님이 2014년 12월 11일 답변
답변 감사합니다. 말씀해주신대로 match_parent에서 height의 값을 0px로 해주었지만 변함이 없습니다 ㅠㅠ
...