Android shape相关
来源:互联网 发布:安庆市网络问政 编辑:程序博客网 时间:2024/06/18 08:39
官方的一些说明是如下,列出了所有的属性:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > //从这里可以看出,shape可以画四种图案:矩形,椭圆,线,环 <corners android:radius="integer" //整体设置圆角,下面四个属性是单独设置圆角 android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" /> //圆角设置 <gradient android:angle="integer" android:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:useLevel=["true" | "false"] /> //渐变设置 <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> //内边距 <size android:width="integer" android:height="integer" /> <solid android:color="color" /> //颜色填充 <stroke android:width="integer" android:color="color" android:dashWidth="integer" android:dashGap="integer" /> //边框设置</shape>
shape文件要在Drawable中,定义完成 了shape之后,布局在view的background中就行了。如下 <Button android:layout_marginTop="12dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="圆角矩形" android:background="@drawable/shape_rectangle1"/>
具体说一下吧。
直角矩形:直角矩形很简单,改个属性值,填充下颜色就行了
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/colorPrimary"></solid></shape>
圆角矩形:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="10dp"></corners> <solid android:color="@color/colorPrimary"></solid> <padding android:bottom="12dp" android:left="12dp" android:right="12dp" android:top="12dp"></padding></shape>
无填充带边框:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="10dp"></corners> <padding android:bottom="12dp" android:left="12dp" android:right="12dp" android:top="12dp"></padding> <stroke android:width="5dp" android:color="@color/colorAccent"></stroke>//也可以设置一个solid 填充点颜色</shape>
渐变:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/colorPrimary"></solid> <padding android:bottom="12dp" android:left="12dp" android:right="12dp" android:top="12dp"></padding> <!--angle 渐变角度,0:左到右;90:下到上;180:右到左;270:上到下--> <gradient android:startColor="@android:color/white" android:endColor="@android:color/black" android:angle="0"></gradient></shape>
oval其实一般是用来画圆的,设置给一个imageview就行了 。只需要将size属性的宽和高设置成一样的就行了,纯色的圆,渐变的圆:
纯色的原:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/colorPrimary"></solid> <size android:height="100dp" android:width="100dp"></size></shape>
将一个圆设置成颜色渐变的:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:height="100dp" android:width="100dp"></size> <gradient android:centerX="0.5" //渐变的x轴起始位置,选择0-1,0.5代表的是圆心位置 android:centerY="0.5" //渐变的y轴起始位置,选择0-1,0.5代表的是圆心的位置 android:type="sweep" android:startColor="@color/colorPrimary" android:endColor="@color/colorAccent"></gradient></shape>
在渐变中的type属性中有三个值:linear 线性渐变,默认的渐变类型
radial 放射渐变,设置该项时,android:gradientRadius也必须设置
sweep 扫描性渐变
线:一般所讲的线就是直线或者虚线,在布局中,线的view你可以直接用一个linearlayout就行了,在background中设置shape为一个线就可以。
虚线:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1dp" android:color="@color/colorAccent" android:dashGap="3dp" //虚线的间距宽度 android:dashWidth="4dp"> //虚线的宽度
</stroke> <size android:height="3dp"></size> //注意:这里的这个height要大于stroke中的width</shape>
虚线在设置的时候一定要加上layertype属性为software,否则看不见虚线<LinearLayout android:layout_marginTop="12dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layerType="software" android:background="@drawable/shape_line"></LinearLayout>
直线:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1dp" android:color="@color/colorAccent"></stroke> <size android:height="3dp"></size></shape>
纯色的环:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:useLevel="false" android:thickness="10dp"> <!--useLevel需要设置为false--> <solid android:color="@color/colorAccent"></solid></shape>颜色渐变的环:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:useLevel="false" android:thickness="10dp"> <!--useLevel需要设置为false--> <solid android:color="@color/colorAccent"></solid> <gradient android:startColor="@color/colorAccent" android:endColor="@color/colorPrimary" android:type="sweep"></gradient></shape>
比较粗糙,以后用到的时候根据需求再仔细研究吧。
阅读全文
0 0
- Android 开发-Shape相关
- Android shape相关
- android 中样式修改关于shape 的相关问题
- [Android进阶笔记]XML相关——Selector、Shape、Styles
- android:shape
- Android Shape
- android shape
- android:shape
- android shape
- android shape
- Android Shape
- android:shape
- Android Shape
- Android Shape
- android shape
- android shape
- android shape
- Android:shape
- 2017 Multi-University Training Contest
- 每日英语阅读(二十)
- Intent跳转传值(ImageLoader加载图片)
- 2017.07.27回顾 ET和RT比较 高级切片 argsort barplot(yerr=) xgb.plot_importance
- 引用---基本特性
- Android shape相关
- js和servlet之间用json的数据格式进行交互
- UI设计切图规范指南
- hdu 3333 Turing Tree (主席树)
- OKhttp的简单使用
- 关于mybatis动态创建数据库表的相关操作
- 类似dubbo的分布式RPC框架
- 图像处理之提取水平线和垂直线
- kafka测试类