如何使用shape来画半圆和画虚线
2016-05-20 16:23
274 查看
一、很多人对于使用shape画圆可能会比较熟悉,这里也奉上代码
shape可以绘制矩形环形以及椭圆,所以只需要用椭圆即可,在使用的时候将控件比如imageview或textview的高度设置成一样就是正圆,solid表示填充色,stroke则表示边框线,所以两者结合可以实现带边缘的圆,当然也可以直接加上size控制高宽。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape:"oval"
android:useLevel="false">
<solid android:color="@color/red"/>
<stroke android:width="1dp"
android:color="@color/white"/>
<size android:width="20dp"
android:height="20dp"/>
</shape>
二、现在就说下如何画半圆,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape = "rectangle">
<soild android:color = "@color/white"/>
<corners
android:bottomLeftRadius = "0dp"
android:bottomRightRadius = "10dp"
android:topLeftRadius = "0dp"
android:topRightRadius = "10dp"/>
使用的地方:
<imageview
android:layout_width = "10dp" //这边的宽高要和shape当中的corners配合使用
android:layout_height = "20dp"
android:background = "@drawable/shape"/> //上面的shape
画半圆的关键所在是shape当中的corners和使用的控件(imageview)的width和height配合使用,而且比较坑的是在xml的预览界面当中看不出效果,需要跑真机才能看出效果。
三、最后讲下如何画虚线
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line"> //这句话一定不要漏了
<stroke
android:width = "1dp"
android:color = "#cfcfcf"
android:dashGap = "5dp"
android:dashWidth = "4dp"/>
<size android:height = "1dp"/> //虚线的高度
</shape>
需要注意的是在使用的时候需要关掉硬件加速:android:hardwareAccelerated = "false"
shape可以绘制矩形环形以及椭圆,所以只需要用椭圆即可,在使用的时候将控件比如imageview或textview的高度设置成一样就是正圆,solid表示填充色,stroke则表示边框线,所以两者结合可以实现带边缘的圆,当然也可以直接加上size控制高宽。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape:"oval"
android:useLevel="false">
<solid android:color="@color/red"/>
<stroke android:width="1dp"
android:color="@color/white"/>
<size android:width="20dp"
android:height="20dp"/>
</shape>
二、现在就说下如何画半圆,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape = "rectangle">
<soild android:color = "@color/white"/>
<corners
android:bottomLeftRadius = "0dp"
android:bottomRightRadius = "10dp"
android:topLeftRadius = "0dp"
android:topRightRadius = "10dp"/>
使用的地方:
<imageview
android:layout_width = "10dp" //这边的宽高要和shape当中的corners配合使用
android:layout_height = "20dp"
android:background = "@drawable/shape"/> //上面的shape
画半圆的关键所在是shape当中的corners和使用的控件(imageview)的width和height配合使用,而且比较坑的是在xml的预览界面当中看不出效果,需要跑真机才能看出效果。
三、最后讲下如何画虚线
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line"> //这句话一定不要漏了
<stroke
android:width = "1dp"
android:color = "#cfcfcf"
android:dashGap = "5dp"
android:dashWidth = "4dp"/>
<size android:height = "1dp"/> //虚线的高度
</shape>
需要注意的是在使用的时候需要关掉硬件加速:android:hardwareAccelerated = "false"
相关文章推荐
- linux误操作删除掉var(rm /var/*)目录导致的问题,及解决方法
- Android Studio 快捷键使用
- 线程
- Android 自定义日历控件
- 输入法评价
- cocoapod 安装
- zepto tap “点透”的解决
- Triangle
- iOS学习之——NSString
- java设计模式
- AndroidStudio导入项目一直卡在Building gradle project info最快速解决方案
- Linux下的文件有三个“时间”
- EventBus使用详解(二)——EventBus使用进阶
- 自定义控件--View篇学习总结
- 课堂实验--贴吧找水王问题
- jquery 页面滚动到底部自动加载插件集合
- 七牛evm云主机安装配置以及删除mysql
- RGB、HSB\HSV、HSL三种颜色空间的原理理解与转换
- 图片缓存之内存缓存技术LruCache,软引用
- Mac OS安装nginx with nginx-stick-module-ng