2013-08-27 37 views
4

我想做一個具有可繪製漸變作爲背景的活動,並將在其背景上顯示4個面板(RelativeLayout)。現在我想讓4個面板透明(例如50%),以便可以看到漸變背景。我搜索谷歌,但我發現只有這樣做的方式與活動不佈局。如何做我想要的?android- transparent RelativeLayout

回答

12

您可以創建一個drawableshape內容。把你的風格放在裏面。

樣品:

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

    <solid android:color="#77ffffff"/> 

</shape> 

創建一個名稱的文件,如在資源路徑的繪製文件夾sampleBackground.xml。和你的面板的 背景屬性設置爲它:

android:background="@drawable/sampleBackground" 
9

如果您想使其透明,則可以使用alpha屬性進行佈局。它可用於以下方式: -

<RelativeLayout 
    android:id="@+id/yourRelativeLayoutID" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:alpha="0.7" 
    android:gravity="bottom"> 
</RelativeLayout> 

設置alpha值在0.1到1.0之間。這取決於你想要的透明度。

希望這會有所幫助。 :)

+0

@Soheil你可以發佈你想要什麼樣的佈局中的任意截圖? – DroidDev

3

您可以使用此:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/transparent" > 
</RelativeLayout> 
+0

但它使面板沒有任何背景... – Soheil

1

我能夠通過指定背景顏色得到RelativeLayout的元素透明背景:

<RelativeLayout 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:background="@color/modal_background" > 
</RelativeLayout> 

而在我的colors.xml中,我使用alpha值創建了一個名爲modal_background的顏色。這個特殊的例子是黑色(#000000)與CC alpha值:

<resources> 
    <item name="modal_background" type="color">#CC000000</item> 
</resources>