3

私の LinearLayout には 2 つの子 ViewGroups があり、基本的にはそれぞれに 50% のスペースを確保したいのですが (それは完了しています)、これらの ViewGroups の 1 つのコンテンツが 50% よりもはるかに小さい可能性もあります。 、2番目のビューを残りのスペースと一致させる方法はありますか?

今、私のレイアウトは次のようになります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:orientation="horizontal"
    android:weightSum="1">

<include layout="@layout/layout1"
    android:layout_width="0dip"
    android:layout_weight="0.5"
    android:layout_height="match_parent" />

<include layout="@layout/layout2"
    android:layout_width="0dip"
    android:layout_weight="0.5"
    android:layout_height="match_parent" />

そして、私が達成したいのは、1 つのレイアウト wrap_content ですが、50% 以下であり、2 番目のレイアウトが残りのスペースを埋めることです。

前もって感謝します!

4

1 に答える 1

4

線形レイアウト内に 2 つのレイアウトを作成し、それぞれに を指定しlayout_weightます0.5。次に、これらのそれぞれに、特性を持つビュー グループを配置しますandroid:layout_width="wrap_content"。そのような -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal"
android:weightSum="1">
    <LinearLayout
       android:layout_weight="0.5"
       ......
<include layout="@layout/layout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
     android:layout_weight="0.5"
     ......
<include layout="@layout/layout2"
    android:layout_width="0dip"
    android:layout_weight="0.5"
    android:layout_height="match_parent" />
<LinearLayout/>
于 2012-12-01T20:01:28.720 に答える