嵌套视图的RelativeLayout规则

问题描述:

我遇到了一个我不知道如何解决的问题。 我会用一个简单的例子来描述它。嵌套视图的RelativeLayout规则

这里是我的布局XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="50dp" 
     android:layout_marginTop="120dp" > 

     <View 
      android:id="@+id/ttt" 
      android:layout_width="200dp" 
      android:layout_height="200dp" 
      android:background="@color/whiteish" /> 
    </FrameLayout> 

    <View android:layout_below="@+id/ttt" 
     android:layout_width="30dp" 
     android:layout_height="10dp" 
     android:background="@color/facebook_gradient_high" > 
    </View> 

</RelativeLayout> 

结果:

Result

蓝色的小矩形被放置在大白色方形下方。我不敢肯定,这是因为白色广场不是RelativeLayout的直接子女。不过,我想达到预期的效果。我会怎么做?

编辑: 我也尝试将边距直接应用到View而不使用FrameLayout。这也不会产生所需的结果,因为我不希望在定位与其相关的其他视图时将边距考虑在内。

给你的FrameLayout像

android:id="@+id/framelayout" 

一个ID,并把下面的白色大一个这样

android:layout_below="@+id/framelayout" 

编辑您的蓝色矩形: 只是要清楚你要以此为所需结果?

enter image description here

+0

检查我的编辑。这不会按我想要的方式工作,因为它会考虑利润率。当我将它从“下”改为“上”时,会发生这种情况。这个例子没有描绘,但我希望你明白我的意思。 – Paul 2013-05-02 10:23:45

+0

如何将蓝色视图添加android:layout_alignParentLeft =“true”。 – 2013-05-02 10:28:34

+0

不幸的是,我不明白这将如何解决我的问题。 – Paul 2013-05-02 10:31:07