2015-02-24 136 views
1

我想创建一个形状像下面的图像通过XML。搜索了很多,使角落顺利,但无法使其通过!创建一个圆形

enter image description here

+0

如果您创建了圆角的ususal形状,设置宽度长于具有视图的高度形状为backround,它会是这样的... – Opiatefuchs 2015-02-24 11:02:56

+0

不可能在xml中做到这一点,试试自定义Shape类而不是 – pskink 2015-02-24 11:03:14

+0

isit解决了吗? – 2015-02-24 11:12:59

回答

2

尝试这样的: 创建文件夹绘制一款Android这样的XML:

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

    <corners 
     android:bottomLeftRadius="10dp" 
     android:bottomRightRadius="10dp" 
     android:topLeftRadius="10dp" 
     android:topRightRadius="10dp" /> 

    <solid android:color="#96000000" /> 

    <padding 
     android:bottom="1dp" 
     android:left="5dp" 
     android:right="5dp" 
     android:top="1dp" /> 

</shape> 
+0

检查一次它不可能在xml中。它没有得到确切的输出,通过使用画布是可能的。 – 2015-02-24 11:16:16

+0

有可能尝试上面的代码。 – 2015-02-24 11:17:55

+0

我已经试过了。一旦没有得到确切的输出,重新检查。 – 2015-02-24 11:18:52

1

以补充@NoName答案,以获得全面的效果,你的形状的高度必须等于每边的半径。

+2

这是正确的答案!我希望别人也会赞赏它:) – 2015-02-24 11:23:45

0

您创建绘制文件夹中的XML

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

<!-- view background color --> 
<solid android:color="#19A347" > 
</solid> 


<!-- If you want to add some padding --> 
<padding 
    android:bottom="2dp" 
    android:left="5dp" 
    android:right="5dp" 
    android:top="2dp" > 
</padding> 

<!-- Here is the corner radius --> 
<corners 
    android:bottomLeftRadius="20dp" 
    android:bottomRightRadius="20dp" 
    android:topLeftRadius="20dp" 
    android:topRightRadius="20dp" > 
</corners>