2012-04-18 22 views
1

說一個佈局我想讓裏面一個又一個不同的背景顏色中的一種佈局,但一旦我添加背景顏色到內部佈局(frameLayout6在這種情況下),外佈局的背景變得透明...背景失去顏色,如果裏面有

enter image description here

任何想法可能是錯誤的?

謝謝!

   <FrameLayout 
        android:id="@+id/frameLayout5" 
        android:layout_width="160px" 
        android:layout_height="160px" android:background="#FFFFFF" android:layout_marginLeft="20px"> 

        <FrameLayout 
         android:id="@+id/frameLayout6" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" android:layout_margin="5px"> 
        </FrameLayout> 

       </FrameLayout> 

回答

1

內部佈局(frameLayout6)位於framelayout5之上,所以如果您在內部佈局中設置背景,則無法看到framelayout5。

編輯:

我不知道爲什麼這種行爲發生,但你可以做到這一點

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RelativeLayout android:id="@+id/frameLayout5" 
     android:layout_height="160dp" 
     android:layout_marginLeft="20dp" android:layout_width="160dp"> 

     <View android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff00ff"/> 

     <RelativeLayout android:layout_width="fill_parent" 
      android:background="#ff0000" android:layout_height="fill_parent" 
      android:layout_margin="50dp" android:drawingCacheQuality="auto"> 
     </RelativeLayout> 

    </RelativeLayout> 
</LinearLayout> 
+0

但它有餘量,即使我添加填充物,但它仍然是不可行的。 – 2012-04-18 20:09:09

+0

對於保證金的情況,您必須查看framelayout5的背景。在填充的情況下,你必須看到framelayout6 http://stackoverflow.com/questions/4619899/difference-between-a-views-padding-and-margin – FUBUs 2012-04-18 20:10:15

+0

的只是背景見上圖。 :) – 2012-04-18 20:13:07