FrameLayout wrap_content

hol*_*taf 3 android android-layout

我有FrameLayout的问题.我想创建FrameLayout,它将拥有它的第一个孩子的身高,第二个孩子将获得它的父亲的身高(100dp在这个例子中).但我得到的是FrameLayout正在填充屏幕(match_parent).这是我的xml.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <View
        android:layout_width="match_parent"
        android:layout_height="100dp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

我如何让FrameLayout像它的第一个孩子一样大,第二个孩子和它的父母一样大?我需要使用不同的父母吗?

Aab*_*ani 11

使用RelativeLayout肯定会为您提供您想要实现的目标:

  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <View
            android:id="@+id/view_id_1"
            android:layout_width="match_parent"
            android:layout_height="100dp" />

        <View
            android:id="@+id/view_id_2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/view_id_1"
            android:layout_alignTop="@+id/view_id_1" />
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!