1

に基づいてUIを設定したいandroid:layout_weight.Iは次のコード構造を持っています

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<ListView
    android:id="@+id/relatedContent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="60dp"
    android:layout_weight="50"
    here=""
    problem=""
    android:cacheColorHint="@android:color/transparent"
    android:divider="@drawable/divider"
    android:listSelector="@drawable/listview_selector_color" >
</ListView>

すべてが正常に機能しますが、ListView id を設定すると、すべてのレイアウトがストレッチされます。

4

3 に答える 3

1

以下のように xml を変更する必要があります。

//alter both LinearLayout as
android:layout_weight="25"
android:layout_height="0dp"

//alter ListView as
android:layout_weight="50"
android:layout_height="0dp"
android:isScrollContainer="false"
于 2012-10-15T10:19:49.600 に答える
0

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<ListView
    android:id="@+id/relatedContent"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="60dp"
    android:layout_weight="50"
    android:cacheColorHint="@android:color/transparent" >
</ListView>

于 2012-10-15T10:54:34.927 に答える
0

list viewを内側に入れ、 に与えます。 linear layout次に、幅と高さを にします。layout_weight="50"linear layoutlistviewfill parent

また、linear_layoutを与えるlayout height="0dp"

于 2012-10-15T10:09:52.100 に答える