2011-09-14 203 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