android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
来源:互联网 发布:gifrocket windows 编辑:程序博客网 时间:2024/05/16 17:09
shape使用、渐变色、分割线、边框、半透明、半透明阴影效果。
首先简单了解一下shape中常见的属性。(详细介绍参看 api文档 )
转载请注明:Rflyee_大飞: http://blog.csdn.net/rflyee/article/details/20785495
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > --- 默认为rectangle <corners -- shape=“rectangle”时使用, android:radius="integer" -- 半径,会被下边的属性覆盖,默认为1dp, 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 -- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴 android:width="integer" android:height="integer" /> <solid -- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六就只就OK) android:color="color" /> <stroke -- 指定边框,border,dashWidth和dashGap有一个为0dp则为 android:width="integer" android:color="color" android:dashWidth="integer" -- 虚线宽度 android:dashGap="integer" /> -- 虚线间隔宽度</shape>
注意:
<corners>
1、 android:radius,半 径,会被下边的单个角度半径属性覆盖,默认为1dp,
2、在使用时,如果单独设置四个角度,又大小不一致时,eclipse的graphics preview会报错。但是直接真机运行即可。(比如实线上边直角,下边屈角的效果)
<size>
Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default. When you use the shape in an ImageView
, you can restrict scaling by setting the android:scaleType
to "center"
res/drawable/gradient_box.xml
: <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /></shape>
如图:
2、白色边框、半透明效果
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="16dp" /> <!-- 这是半透明,还可以设置全透明,那就是白色边框的效果了 --> <solid android:color="#80065e8d" /> <stroke android:dashGap="0dp" android:width="4dp" android:color="@android:color/white" /></shape>
如图:
3、分割线效果:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:width="4dp" android:color="@android:color/black" /></shape>
如果:
4、单边屈角效果
<?xml version="1.0" encoding="utf-8"?><shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp"/> <!-- 这是半透明,还可以设置全透明,那就是白色边框的效果了 --> <solid android:color="#ff065e8d" /> <stroke android:dashGap="0dp" android:width="4dp" android:color="@android:color/white" /></shape>如图:
另:附上一份颜色进制图,需要的可以查阅: http://blog.sina.com.cn/s/blog_684a1d160100umuq.html
转载请注明:Rflyee_大飞: http://blog.csdn.net/rflyee/article/details/20785495
推荐文章
- 1. Android开发周报:F8 App开发指南、Android性能优化解析
- 2. 如何自学Android
- 3. 浮窗开发之窗口层级
- 4. Agera官方Wiki翻译(三)——被观察者和 updatables
- 5. Android开发技术周报 Issue#78
- 6. 实战Kotlin@Andorid(二):界面构建与扩展方法
相关推刊
- 刊主:pillow 《默认推刊》3
- 刊主:freezb《android》2
- 刊主:Coco泫 《默认推刊》315
热门文章
- 1. Android 插件化的 过去 现在 未来 - 张涛
- 2. Android开发周报:F8 App开发指南、Android性能优化解析
- 3. 如何自学Android
- 4. 浮窗开发之窗口层级
- 5. Android SharedPreferences 源码分析
0 0
- 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的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- Cayley定理在组合数学中的应用
- android 布局
- 《VR入门系列教程》之17---发布第一个应用
- Android EditText不获取焦点和监听
- maven核心,pom.xml详解
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- OLTP报表和OLAP报表
- 《VR入门系列教程》之18---Oculus代码剖析
- 步步学习python之环境安装:Vagrant+Ubuntu+Emacs+Virtualenv+Python3开发环境的搭建(Mac电脑下)4
- TCP 的那些事儿(下)
- android笔记之Eclipse ADT的 keystore证书规格及修改证书密码别名
- 剑指offer:按之字形顺序打印二叉树
- 动态规划-最长上升子序列
- 使用IntelliJ IDEA开发SpringMVC网站(三)数据库配置
我来评几句
登录后评论已发表评论数(0)