2016-05-18 322 views
-3

如何给背景颜色渐变,如下图所示 Image with gradient颜色渐变的背景

如何编写代码,以便显示图像出现在附件

+0

你尝试过什么到目前为止? –

+0

如果您可以发布您尝试过的一些示例,这将有所帮助,因此我们可以帮助您诊断出现问题的原因。 – theatlasroom

回答

0

这里试试这个在:

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

<gradient 
    android:angle="90" 
    android:centerColor="Your Color" 
    android:endColor="Your Color" 
    android:startColor="Your Color" 
    android:type="linear" /> 



</shape> 
0

/RES /绘制创建gradient.xml

<?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> 

,并在/RES /布局main.xml中布局文件:

<?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" 
android:background="@drawable/gradient"> 

</LinearLayout> 

您可以通过更换机器人指定角:值和开始/结束颜色通过替换android:startColorandroid:endColor

0

制作一个xml文件水库>绘制文件夹命名background.xml和下面编辑:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<gradient 
android:type="radial" 
android:centerX="50%" 
android:centerY="50%" 
android:startColor="#FFFF8205" 
android:endColor="#FFF7F7F7" 
android:gradientRadius="100"/> 
</shape> 
在activity_main.xml中的文件引用

现在这个作为父布局的背景

<LinearLayout 
....... 
android:background="@drawable/background"> 
..... 
</LinearLayout>