2011-09-14 73 views
4

我有一個典型的登錄屏幕(表格佈局)。我想要做的是圍繞這些控件繪製一個矩形,並在其中放入漸變。我如何在XML中做到這一點?背景漸變

回答

9

創建gradient.xml/res/drawable

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="#FFFFFF" 
     android:endColor="#00000000" 
     android:angle="45"/>  
</shape> 

,並在佈局文件中添加android:background="@drawable/gradient"到了控制措施,

+0

IT工作!!!!!!!!!!!!!!!!謝謝 – user533844

6

使用可繪製的漸變背景創建佈局,並在其內部實現您的真實佈局。

例如,創建mygrandientbg_xml在繪圖資源目錄,如:

<shape android:shape="rectangle" xmlns..."> 
<gradient 
    android:startColor="#255779" 
    android:centerColor="#3e7492" 
    android:endColor="#a6c0cd" 
    android:angle="90" /> 
</shape> 

然後創建這樣的

<FrameLayout 
    .... 
    android:background="@drawable/mygrandientbg" 
    android:padding=20dip 
> 
put you layout here and set it to "centered" 

一個FrameLayout裏你可以找到關於可繪製形狀這裏更多的信息: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

+0

它的工作容器propierties !!!!!!!!!!!!謝謝 – user533844

+0

好!請標記我的答案是正確的。 – JohnUopini