gpt4 book ai didi

android - FrameLayout wrap_content

转载 作者:太空宇宙 更新时间:2023-11-03 11:43:51 25 4
gpt4 key购买 nike

我对 FrameLayout 有疑问。我想创建 FrameLayout,它将具有第一个 child 的高度,第二个 child 将获得父级的高度(本例中为 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 和它的第一个 child 一样大,让第二个 child 和它的 parent 一样大?我需要使用不同的 parent 吗?

最佳答案

使用 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>

希望这对您有所帮助!

关于android - FrameLayout wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22016424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com