2013-04-12 90 views
20

我有一個黃色RelativeLayout包含一個較高的紅色LinearLayout無法獲得clipChildren = false屬性

爲了使整個LinearLayout可見,我設置android:clipChildren="false",但這並不會達到預期效果:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="44dp" 
    android:background="#FFFF00" 
    android:clipChildren="false" > 

    <LinearLayout 
     android:layout_width="50dp" 
     android:layout_height="100dp" 
     android:background="#FF0000" 
     android:orientation="vertical" > 

    </LinearLayout> 

</RelativeLayout> 
  • android:clipChildren="true"

enter image description here

與按預期修剪的紅色LinearLayout

  • android:clipChildren="false"

enter image description here

其中LinearLayout高度被削波,並且在佈局中設置的寬度不尊重。

怎麼了?

編輯

如果我包裹在兩個維度匹配其父LinearLayout容器中,我得到了相同的結果(我檢查了的LinearLayout容器的容器充滿整個屏幕)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="44dp" 
     android:background="#FFFF00" 
     android:clipChildren="false" > 

     <LinearLayout 
      android:layout_width="50dp" 
      android:layout_height="100dp" 
      android:background="#FF0000" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </RelativeLayout> 

</LinearLayout> 

EDIT 2

如果我把父的LinearLayout的android:clipChildren="false"屬性,我得到如下:

enter image description here

+0

相對佈局具有機器人:layout_height = 「44dp」。它本身就是由它的父親 – njzk2

+0

加密的,我用setContentView(R.layout.test);直接設置了這個佈局。沒有明確的父母。根視圖組是否填滿整個屏幕?爲什麼要修改LinearLayout的寬度? – jul

+0

@ njzk2:爲​​了做更多的測試,我嘗試了不同的佈局,並且它仍然不起作用(請參閱我的編輯) – jul

回答

13

另外設置

android:clipToPadding="false" 

除了:

android:clipChildren="false" 
46

android:clipChildren="false"讓每個孩子外得出自己的在父母的範圍內。它不允許孩子在父母之外繪畫。爲此,您需要在祖父母上設置android:clipChildren="false"(以及)。

我認爲你看到的顏色只是因爲顏色沒有固有的界限。如果沒有任何東西被剪掉,顏色就會永遠消失。我的理論是,如果你使用拉伸的1x1像素而不是顏色,事情就會不同。