2012-09-14 11 views
9

나는 다음과 같은 XML 레이아웃이 있습니다이 LinearLayout은 android : layout_height = "wrap_content"를 사용해야합니까?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" // ==> here I get the error. 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="2dip" 
     android:background="#298EB5" 
     android:orientation="horizontal" /> 


    </LinearLayout> 
</ScrollView> 

을하지만 난 보풀 메시지를 얻을 :

이있는 LinearLayout은 안드로이드를 사용한다 : layout_height = "wrap_content"를

왜 내가 어떻게해야합니까를 이 메시지?

답변

10

LinearLayout은 요소를 나란히 또는 서로 겹쳐서 배치하도록 설계되었습니다. 내 생각 엔이 보풀 경고 인해 ScrollView

Documentation에 virtical 스태킹을 권장하는 것입니다 : 다른 후 하나를 적층 된있는 LinearLayout의

"어린이, 때문에 수직 목록은 행 당 하나의 아이를해야합니다 (가로, 세로 또는 가로)는 높이가 한 줄 (높이가 가장 큰 어린이의 높이와 안쪽 여백)이 될 것입니다 .LinearLayout은 어린이와 중력의 마진 (오른쪽, 가운데 또는 왼쪽 정렬)을 존중합니다 어린이."

+3

서식을 지정해 주셔서 감사합니다. –

3

의 린트 경고 당신은 내용을 필요로

android:layout_height="wrap_content" 

wrap_content는 현재 부가 기능에 따라 높이를 차지 사용해야합니다. 여기 레이아웃의 높이를 요구에 따라 바꿈

4

오류가 아니지만 경우에 따라 원하지 않는 결과가 발생하기 때문에 권장하지 않습니다. 나는 scrollview를 사용하면서 Romain에 의해 article을 따른다. 이것이 메시지의 이유를 설명하기를 바랍니다.

관련 문제