2016-05-18 321 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>