为什么Linearlayout无法正确显示嵌套的Framelayout



我有一个XML布局,在该布局中,我将framelayout嵌套在线层中,并试图将一个兄弟姐妹查看组堆叠在Framelayout的顶部。它根本不显示同级观看小组,而只是Framelayout。我想获得一些帮助,以了解为什么将根视图组替换为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本身就填充了屏幕。当我将root ViewGroup更改为用Layout_height和Layout_width定义的RelativElayout到" Match_parent"时,我将获得我的预期输出,其中imageView和两个TextViews在Framelayout的顶部显示。我对它的工作方式感到困惑,因为我没有指定与" bottomof"或" topof"的儿童ViewGroups/View的任何相关参数。

relativelayout有线度延迟没有的调整大小的预兆或重量分布没有吗?我一直在网上寻找,但不幸的是没有找到答案。

谢谢!

在您显示的代码中,第一个FrameLayout匹配父母的高度,因此下面的LinearLayout将下方推开(Y轴,而不是z轴)FrameLayout。这是因为他们的父母是LinearLayout,它在垂直的另一个(Y轴)(Y轴)下方的孩子(不重叠)(如每片劳动纸中,每个视图都是纸张正方形)。

如果您希望孩子FrameLayoutLinearLayout在另一个(z轴)的顶部,他们的父母必须是FrameLayout,它将其安排在Z轴上重叠的一个孩子(AS AS)在一堆纸质纸中)。

关于为什么RelativeLayout不指定布局参数会给您预期的行为,这是因为默认值是将子视图放在容器的左上角角(来自RelativeLayout文档):

默认情况下,所有子视图均在布局的顶部绘制,因此您必须使用Relativelayout.layoutparams可用的各种布局属性来定义每个视图的位置。

您应该从frameLayout中删除match_parent,因为垂直方向的线层将视图放置在一个接一个地放置。

在您的情况下,Framelayout负责将整个设备屏幕屏幕删除,因此剩下的视图将被推开。

最新更新