【发布时间】:2014-01-31 00:13:55
【问题描述】:
我有一个 XML 布局,其中我将一个 FrameLayout 嵌套在一个 LinearLayout 中,并尝试在 FrameLayout 顶部堆叠一个同级查看组。它根本不显示同级查看组,而只是显示 FrameLayout。我想请一些帮助来理解为什么将根 ViewGroup 替换为 RelativeLayout 会产生预期的输出。
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainFrameLayout"
android:background="#787878"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/ImageView01"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:src="@drawable/download"
android:adjustViewBounds="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="40sp"
android:text="Top text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="right"
android:text="bottom_text"
android:textColor="#fff"
android:textSize="50sp" />
</LinearLayout>
</LinearLayout>
我只看到 FrameLayout 本身填满了屏幕。当我将根 ViewGroup 更改为使用 layout_height 定义的 RelativeLayout 并将 layout_width 更改为“match_parent”时,我得到了预期的输出,其中 ImageView 和两个 TextView 都显示在 FrameLayout 的顶部。我对它是如何工作的感到困惑,因为我没有为子 ViewGroups/View 指定任何 RelativeLayout 参数,例如“bottomof”或“topof”。
RelativeLayout 有没有 LinearLayout 没有的调整大小属性或权重分布吗?我一直在网上找,可惜没有找到答案。
谢谢!
【问题讨论】:
-
如果你仔细观察,你没有在框架布局标签中添加任何东西
标签: android android-layout android-linearlayout android-relativelayout android-framelayout