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"

举个栗子:

1、渐变色

res/drawable/gradient_box.xml :

<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="#FFFF0000"android:endColor="#80FF00FF"android:angle="45"/><paddingandroid:left="7dp"android:top="7dp"android:right="7dp"android:bottom="7dp"/><cornersandroid: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

android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)的更多相关文章

  1. android shape.xml 属性详解

    转载源:http://blog.csdn.net/harvic880925/article/details/41850723 一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标 ...

  2. Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  3. Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  4. 《Android NFC 开发实战详解 》简介+源码+样章+勘误ING

    <Android NFC 开发实战详解>简介+源码+样章+勘误ING SkySeraph Mar. 14th  2014 Email:skyseraph00@163.com 更多精彩请直接 ...

  5. Android开发之InstanceState详解

    Android开发之InstanceState详解   本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...

  6. ANDROID L——Material Design详解(UI控件)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

  7. Cordova 打包 Android release app 过程详解

    Cordova 打包 Android release app 过程详解 时间 -- :: SegmentFault 原文 https://segmentfault.com/a/119000000517 ...

  8. 给 Android 开发者的 RxJava 详解

    我从去年开始使用 RxJava ,到现在一年多了.今年加入了 Flipboard 后,看到 Flipboard 的 Android 项目也在使用 RxJava ,并且使用的场景越来越多 .而最近这几个 ...

  9. Android中Intent组件详解

    Intent是不同组件之间相互通讯的纽带,封装了不同组件之间通讯的条件.Intent本身是定义为一个类别(Class),一个Intent对象表达一个目的(Goal)或期望(Expectation),叙 ...

随机推荐

  1. CentOS Device eth0 does not seem to be present 解决方案

    1. vi /etc/udev/rules.d/70-persistent-net.rules 记录eth1 的网卡地址 2.vi /etc/sysconfig/network-scrpits/ifc ...

  2. php5.6安装

    # yum --enablerepo=remi,remi-php56 install php-fpm php-common php-mysql php-opcache php-pear php-gd ...

  3. ng的数据绑定

    ng创建了一个自己的事件循环,当浏览器事件(常用的dom事件,xhr事件等)发生时,对DOM对应的数据进行检查,若更改了,则标记为脏值,并进入更新循环,修改对应的(可能是多个) DOM的参数.这样就实 ...

  4. 滚动条响应鼠标滑轮事件实现上下滚动的js代码

    <script type="text/javascript"> var scrollFunc=function(e){ e=e || window.event; if( ...

  5. hadoop 异常 ls: Cannot access .: No such file or directory.

    bin/hadoop dfs -lsls: Cannot access .: No such file or directory. bin/hadoop dfs -ls /用这个命令代替试试 原因是格 ...

  6. 在SystemOut.log中发现HMGR0152W: 检测到CPU 饥饿的消息 <转载>

    今天系统报警了!!!!!顿时人又不好了!!!查看系统日志, 报错如下: Did not receive adequate CPU time slice. Last known CPU usage ti ...

  7. ASP.NET Routing

    ASP.NET Routing Other Versions   ASP.NET routing enables you to use URLs that do not have to map to ...

  8. Ehcache中配置详解

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...

  9. Java 利用SWFUpload多文件上传 session 为空失效,不能验证的问题 swfUpload多文件上传

    Java 利用SWFUpload多文件上传 session 为空失效,不能验证的问题(转) 我们都知道普通的文件上传是通过表单进行文件上传的,还不能达到异步上传的目的.通过使用某些技术手段,比如jqu ...

  10. 14.5.2.2 autocommit, Commit, and Rollback

    14.5.2.2 autocommit, Commit, and Rollback 在InnoDB,所有的用户活动发生在一个事务里, 如果自动提交模式是启用的, 每个SQL语句形成一个单独的事务.默认 ...