9

私は次のxmlレイアウトを持っています:

<?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>

しかし、私はlintメッセージを受け取ります:

このLinearLayoutはandroid:layout_height="wrap_content"を使用する必要があります

なぜこのメッセージが表示されるのですか?

4

3 に答える 3

10

LinearLayoutは、要素を横に並べたり、重ねたりするように設計されています。私の推測では、この lint 警告は、ScrollView

ドキュメンテーション:

「LinearLayout のすべての子は次々に積み重ねられるため、縦方向のリストは幅に関係なく、行ごとに 1 つの子しか持たず、横方向のリストは 1 行の高さ (最も高い子の高さ、さらにパディング。 LinearLayout は、子の間のマージンと、各子の重力 (右、中央、または左の配置) を考慮します。"

于 2012-09-14T12:24:17.723 に答える
4

リント警告を使用する必要があります

android:layout_height="wrap_content"

wrap_content必要なコンテンツの追加に従って高さを占めます。ここでは、必要に応じてレイアウトラップの高さ

于 2012-09-14T12:21:30.670 に答える
4

これはエラーではありませんが、場合によっては望ましくない結果が生じるため、推奨されません。scrollviewを使用しながら、Romainによるこの記事に従います。これでメッセージの理由が説明されることを願っています。

于 2012-09-14T17:25:54.503 に答える