2014-06-25 27 views

回答

0
int startColor=Color.parseColor("#a6c1de"); 
//you can add as many gradient colors as you want here 
//and include it in the int array while initializing GradientDrawable 
int endColor=Color.parseColor("#aa82b7"); 
GradientDrawable mDrawable=new GradientDrawable(Orientation.LEFT_RIGHT, new int[] startColor,endColor}); 

LinearLayout mLayout=(LinearLayout)findViewById(R.id.your_id); 
mLayout.setBackgroundDrawable(mDrawable); 
+0

謝謝。你節省了我的時間。 – BSKANIA

+0

這只是從左到右的兩種顏色漸變? – Decoy

+0

是的,但你可以在中心添加另一種顏色。 'new int [] startColor,centerColor,endColor}' – makata

5

在這裏,你有一個在線工具,用於創建梯度形狀爲Android:

http://angrytools.com/gradient/

通過點擊Android的選項卡上,你得到的形狀(S)的xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<gradient 
    android:type="linear" 
    android:centerX="47%" 
    android:startColor="#FF70C1FF" 
    android:centerColor="#FFBDC9FF" 
    android:endColor="#FF734080" 
    android:angle="45"/> 
</shape> 

<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="#FF70C1FF" 
    android:centerColor="#FFBDC9FF" 
    android:endColor="#FF734080" 
    android:gradientRadius="47"/> 
</shape> 
+0

什麼不起作用? – Decoy

+0

實際上它給出了線性漸變顏色形狀,但是您可以在圖像中看到它不完全是線性漸變。如果您選擇兩種顏色,則應該從上到下逐個顏色地將燈光調暗。 – BSKANIA

0

Yo你不能使用許多顏色來創建Gradient,就像你的圖像中兩種顏色是線性的。所以你應該使用Image而不是漸變。