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. jQuery慢慢啃之属性(三)

    1.attr(name|properties|key,value|fn)设置或返回被选元素的属性值. $("img").attr("src");//获取属性 $ ...

  2. 关于Asp.Net中避免用户连续多次点击按钮,重复提交表单的处理

    Web页面中经常碰到这类问题,就是客户端多次点击一个按钮或者链接,导致程序出现不可预知的麻烦. 客户就是上帝,他们也不是有意要给你的系统造成破坏,这么做的原因很大一部分是因为网络慢,点击一个操作之后, ...

  3. php基础知识【函数】(8)xml和变量函数

     一.XML函数 参数类型 data    --string,需要解析的数据集. parser  --resource,一个指向要取得字节索引的 XML 解析器的引用.  1.创建和释放XMl解析器 ...

  4. C# 正则表达式、Json

    正则表达式: 正则表达式主要的参考文章:http://www.cnblogs.com/stg609/archive/2009/06/03/1492709.html#anchorD. 需求:将cocos ...

  5. smtp协议

    一.smtp命令 1.HELO 向服务器标识用户身份 2.MAIL 初始化邮件传输mail from: <xxx> 3.RCPT 标识单个的邮件接收人:常在MAIL命令后面可有多个rcpt ...

  6. cf C. Arithmetic Progression

    http://codeforces.com/contest/382/problem/C 题意:给你n个数,然后让你添加一个数使得n+1个数能形成这样的规律,a[1]-a[0]=a[2]-a[1]=a[ ...

  7. Android Wear开发 - 数据通讯 - 第四节 : 数据封装(解决不能序列化问题)

    一. 前言 背景 一开始笔者在研究数据发送与接收的时候,看到Wear数据类DataMap除了可以put基本类型外,还有个fromBundle方法来构建一个DataMap对象.所以一口气的将原本功能上的 ...

  8. java数组排序之冒泡排序

    上一篇文章说了,选择排序. 选择排序的原理就是,先确定第一个格子当中的数字是最小的,之后确定第二个格子是其他数字中最小的依次类推. 这一节当中我们来看下冒泡排序: 思路: 1.首先拿第一个数字跟第二个 ...

  9. How to add alias on Mac(It's common for most system)

    Since these files are hidden you will have to do an ls -a to list them. If you don't have one you ca ...

  10. matlab中如何求某一个矩阵的标准差和均值

    方法: 先reshape成行向量或者列向量 然后,利用mean函数,std函数. 构造测试数据,可以利用random函数,就好.利用这个函数,可以构造不同分布的随机数列(或 矩阵). 如: >& ...