2013-11-27 47 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