2013-11-27 45 views
1

如何獲得此漸變背景的按鈕視圖?橢圓形按鈕在Android與漸變背景

我GOOGLE了很多,但還沒有找到

,我認爲一個重疊其他的是因爲相對佈局的..

enter image description here

+0

看到類似的問題回答:http://stackoverflow.com/questions/19797430/android-complex-shape-button/19801248#19801248。如果您之前沒有這樣做,請告訴我,我會嘗試發佈更具體針對您問題的答案。 – RocketSpock

回答

6

創建繪製文件夾中的XML文件:

oval_background.xml

<?xml version="1.0" encoding="utf-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" > 
    <gradient 
     android:startColor="#6586F0" 
     android:centerColor="#D6D6D6" 
     android:endColor="#4B6CD6" 
     android:angle="90"/> 

</shape> 

使用此文件作爲按鈕的背景:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/oval_background" 
    android:id="@+id/ButtonTest" 
    android:text="button"> 
</Button> 
+0

有沒有辦法讓它看起來是圓形的? –

+0

@RuchirBaronia橢圓形適合包含視圖的尺寸,然後有一個圓的視圖的寬度和高度應該是相同的。您也可以使用''的元素來定義尺寸。請參閱[Shape]的文檔(http://developer.android.com/intl/pt-br/guide/topics/resources/drawable-resource.html#Shape) – ramaral