2012-06-19 180 views
0

試圖弄清楚如何在淺灰色上使漸變顏色變爲「幾乎白色」。作爲一個例子,我可以參考android的ebuddy。你的「夥伴」在一個漸變顏色的列表中。Android漸變顏色aarrggbb

這是如何在android中完成的?我相信它應該使用aarrggbb對不對?

+0

我相信你必須使用一個可繪製作爲背景。選中此問題(http://stackoverflow.com/questions/2928101/android-using-linear-gradient-as-background-looks-banded)以獲取更多詳細信息 – tsukimi

+0

選中此鏈接 - [Shape Drawable](http:/ /developer.android.com/guide/topics/resources/drawable-resource.html#Shape) – Shaiful

回答

2

您可以GradientDrawables創建漸變成機器人,例如:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <gradient 
     android:startColor="#FF808080" 
     android:endColor="#FFFFFFFF" 
     android:angle="270"/> 
</shape> 
0

您可以在res文件夾提拉夾中創建此rectangle.xml文件:(這裏的顏色是你確切想要的)

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

    <gradient android:angle="90" android:startColor="#a3a3a3" android:centerColor="#cfcfcf" android:endColor="#f0f0f0"/> 

現在你可以通過這樣的style.xml文件中定義它使用它作爲屏幕背景:

<style name="screenBackground"> 
     <item name="android:paddingLeft">5dip</item> 
     <item name="android:paddingTop">2dip</item> 
     <item name="android:paddingRight">5dip</item> 
     <item name="android:paddingBottom">2dip</item> 
     <item name="android:background">@drawable/rectangle</item> 
     <item name="android:layout_marginBottom">15dp</item> 
    </style> 

現在用它在你的main.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
    <LinearLayout android:id="@+id/header" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     xmlns:android="http://schemas.android.com/apk/res/android" style="@style/screenBackground"> 

     // All your other elements in the xml file go here. 

    </LinearLayout>