FrameLayout wrap_content

时间:2014-02-25 14:00:37

标签: 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>

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

1 个答案:

答案 0 :(得分: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>

希望这有帮助!