2013-05-02 124 views
0

我遇到了一個我不知道如何解決的問題。 我會用一個簡單的例子來描述它。嵌套視圖的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。這也不會產生所需的結果,因爲我不希望在定位與其相關的其他視圖時將邊距考慮在內。

回答

0

給你的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