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"

をこのメッセージ?コンテンツを必要とするアドオンごとにあなたが

android:layout_height="wrap_content" 

wrap_contentを使用する必要があります

答えて

10

LinearLayoutは、要素を横に並べるか、または重ねて配置するように設計されています。私の推測では、この糸くずの警告が原因ScrollView

Documentationにvirticalスタッキングを推奨していますということです。次々に積層されたのLinearLayoutの

」すべての子どもたち、ので、垂直リストは、行のみにつき一人の子供を持つことになりますLinearLayoutは、子どもと重力のマージン(右、中央、または左揃え)を尊重します(LinearLayoutはそれぞれの高さの高さです)。子。"

+3

フォーマットに感謝します。 –

3

その糸くずの警告は、高さを占めています。 ここではレイアウトの高さは必要に応じてラップします

4

これはエラーではありませんが、場合によっては望ましくない結果を生じるため、示唆されていません。私はスクロールビューを使っている間、Romainによってarticleに従います。これがメッセージの理由を説明してくれることを願っています。

関連する問題