天使漫步IT工作室天使漫步IT工作室

Android利用drawable-xml自定义实心圆和空心圆


Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 110

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 116

一、空心圆

在drawble文件夹新建circle_shape.xml的文件:

配置一个线段宽度为2dp、颜色为红色、大小为10dp的空心圆

<shape android:shape="oval">  
    <stroke android:width="2dp" android:color="#f00"/>    
    <size android:height="10dp" android:width="10dp" />  
</shape>  

如果你的View是宽高相等,就是圆形,即长宽要有值,不能为wrap_content

将TextView的背景设置为空心圆:

<TextView  
        android:layout_width="150dp"  
        android:layout_height="150dp"  
        android:gravity="center"  
        android:background="@drawable/circle_shape"  
        android:text="@string/hello_world" />  

二、实心圆

新建一个实心圆的xml,配置一个线段宽度为2dp、颜色为红色、大小为10dp的实心圆

<shape android:shape="oval">  
    <solid android:width="2dp" android:color="#0f0"/>    
    <size android:height="10dp" android:width="10dp" />  
</shape>  

如果你的View是宽高相等,就是圆形,即长宽要有值,不能为wrap_content

将TextView的背景设置为实心圆如上面代码。

三、拓展:


空心圆和实心圆的区别其实就在于画笔的不同,区别如下:

  • stroke:用笔画,也可以翻译成轮廓,可以画空心的,代码中表示为:Paint.Style.STROKE。
  • solid:固体的,实体的。 也就是实心的,代码表示为:Paint.Style.FILL。

本站原创,欢迎转载,转载敬请标明出处:天使漫步IT工作室 » Android利用drawable-xml自定义实心圆和空心圆
添加新评论


Warning: Use of undefined constant php - assumed 'php' (this will throw an Error in a future version of PHP) in /www/wwwroot/u11u.com/usr/themes/wq/comments.php on line 38