Shape可以定义矩形、椭圆形、线条、圆形

<?xml version="1.0" encoding="utf-8"?>

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<!-- 定义图形角的弧度 -->
<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>

下面是一些例子,修改上面的属性的效果图:

layout就是一个ImageView

<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@drawable/shape_style" />

下面是shape的配置文件内容

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <corners android:radius="0dp" >
</corners> <stroke
android:width="10dp"
android:color="@android:color/holo_blue_light" >
</stroke> </shape>

效果如左边的图,当上面改成

android:radius="50dp"

现在看下gradient,shape的内容如下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <gradient
android:endColor="#ffffffff"
android:startColor="@android:color/holo_blue_bright" >
</gradient> </shape>

效果图如下,

,

修改如下:

    <gradient
android:endColor="#ffffffff"
android:startColor="#ffffffff"
android:centerColor="@android:color/holo_blue_bright"
android:angle="90" >
</gradient>

图如下

下面看下padding,首先ImageView的内容:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_icon"
android:background="@drawable/shape_style" />

shape的内容:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<solid
android:color="@android:color/holo_blue_bright"></solid>
</shape>

最后,看size和stroke

同样是ImageView:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_style" />

shape_style内容:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" > <size android:width="200dp"
android:height="100dp"/>
<stroke
android:width="10dp"
android:color="@android:color/holo_blue_bright" /> </shape>

在shape_style中加入android:dashWidth="5dp"和 android:dashGap="5dp",效果如下:

Stbdroid之ShapeDrawable的更多相关文章

  1. Android ShapeDrawable

    今天做项目碰到一个这样的情况,就是颜色指示框,用的是正方形边框是黑色的,里面填充颜色,颜色值是动态的,为了解决这个问题,查了好多资料,终于找到解决的方法,利用ShapeDrawable,我们自定义一个 ...

  2. Android ShapeDrawable无法上色

    在Android中的View设置背景时,使用ShapeDrawable有可能出现无法上色的问题(最终背景为黑色),例如,使用如下的代码为控件设置颜色时,控件背景将会变成黑色 ShapeDrawable ...

  3. android学习笔记33——资源ShapeDrawable

    ShapeDrawable ShapeDrawable用于定义一个基本的几何图像(如,矩形.圆形.线条.......). 定义ShapeDrawable的XML文件的根元素是<shape.../ ...

  4. ShapeDrawable 资源

    ShapeDrawable 用于定义一个基本的几何图形(如矩形.圆形.线条等),定义 ShapeDrawable 的 XML 文件的根元素是<shape.../>元素,该元素可指定如下属性 ...

  5. 使用(Drawable)资源———ShapeDrawable资源

    ShapeDrawable用于定义一个基本的几何图形(如矩形.圆形.线条等),定义ShapeDrawable的XML文件的根元素是<shape.../>元素,该元素可指定如下属性. and ...

  6. 安卓自定义控件(二)BitmapShader、ShapeDrawable、Shape

    第一篇博客中,我已经Canvas.Paint.Shader.Xfermode这些对象做了总结,而现在这篇文章主要介绍BitmapShader位图渲染,Xfermode如何实际应用,还有形状的绘制.不过 ...

  7. ShapeDrawable做放大镜效果

    引用一下ShapeDrawable的类的说明: java.lang.Object    ? android.graphics.drawable.Drawable      ? android.grap ...

  8. Android ShapeDrawable之OvalShape、RectShape、PaintDrawable、ArcShape

     Android ShapeDrawable之OvalShape.RectShape.PaintDrawable.ArcShape Android图形图像基础之OvalShape.RectShap ...

  9. 关于ShapeDrawable应用的一些介绍(中)之Gradient

    版权声明:本文为博主原创文章,未经博主允许不得转载. Gradient,渐变,是在界面设计中最经常用到的一种技巧,只要涉及到颜色的处理,浓妆淡抹总相宜,说的就是它. 在Android中,当然也提供了这 ...

随机推荐

  1. css的repaint和reflow

    css的repaint和reflow 浏览器为了重新渲染部分或整个页面,重新计算页面元素位置和几何结构(geometries)的进程叫做 reflow. 由于 reflow 是一种浏览器中的用户拦截( ...

  2. 多版本jQuery的使用剖析

    </div> </div> <!-- basic scripts --> <!--[if !IE]> --> <!-- <![endi ...

  3. HDU 5735 Born Slippy(拆值DP+位运算)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5735 [题目大意] 给出一棵树,树上每个节点都有一个权值w,w不超过216,树的根为1,从一个点往 ...

  4. ubuntu apache fastcgi 虚拟主机安装

    1 cp /etc/apache2/sites-available/default /etc/apache2/sites-available/www.domain.com 这里www.domain.c ...

  5. ios蓝牙开发(二)ios连接外设的代码实现

    上一篇文章介绍了蓝牙的技术知识,这里我们具体说明一下中心模式的应用场景.主设备(手机去扫描连接外设,发现外设服务和属性,操作服务和属性的应用.一般来说,外设(蓝牙设备,比如智能手环之类的东西), 会由 ...

  6. web 开发规范

    好久没整理博文了 啰嗦两句  转载至新浪...... 于在未开启cleartype的情况下,一些中文字体在非偶数字号下的显示效果欠佳,所以一般建议使用12.14.16.18.22px等偶数字号.也就 ...

  7. 设置cell背景色半透明

    cell.backgroundColor = [UIColor colorWithRed:(247.0/255.0) green:(151.0/255.0) blue:(121.0/255.0) al ...

  8. 关于TableViewCell高度自适应问题的整理

    TableViewCell高度自适应在网上有很多资料,我只想找出最最最简单的一种方法. 首先梳理一下思路.说到TableViewCell我们第一个想到的问题或许就是cell的复用问题. 1.  [se ...

  9. Android应用开发基础篇(8)-----SurfaceView

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/25/2368069.html 一.概述 SurfaceView也是一个用来画图的部件,不过由于它 ...

  10. (转)Windows重启延迟删除,重命名技术原理

    所谓重启延迟删除技术,就是在操作系统启动前删除或者替换文件! 说起重启延迟删除,大家可能都很陌生,但是实际上,该功能已经被各种软件所采用:如安装Windows 补丁程序(如:HotFix.Servic ...