android中带有渐变背景的椭圆形按钮

android中带有渐变背景的椭圆形按钮,android,android-layout,android-button,Android,Android Layout,Android Button,如何获得渐变背景的按钮视图 我在谷歌上搜索了很多,但没有找到什么 我认为一个对另一个的重叠是因为相对的布局 在drawable文件夹中创建xml文件: oval_background.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <

如何获得渐变背景的按钮视图

我在谷歌上搜索了很多,但没有找到什么

我认为一个对另一个的重叠是因为相对的布局


在drawable文件夹中创建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>

在drawable文件夹中创建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>


请参见类似问题的答案:。如果您之前没有这样做,请告诉我,我将尝试发布一个更具体针对您的问题的答案。请参阅类似的问题答案:。如果您以前没有这样做过,请告诉我,我将尝试发布一个更具体针对您的问题的答案。有没有办法让它看起来是圆形的?@RuchirBaronia一个椭圆形适合包含视图的尺寸,那么要有一个圆形,视图的宽度和高度应该是相同的。您还可以使用
元素来定义尺寸。请参阅文档,了解是否有方法使其看起来是圆形的?@RuchirBaronia椭圆形适合包含视图的尺寸,那么要有一个圆形,视图的宽度和高度应该相同。您还可以使用
元素来定义尺寸。有关详细信息,请参阅文档