shape--> shape属性:

  rectangle: 矩形,默认的形状,可以画出直角矩形、圆角矩形、弧形等

  solid: 设置形状填充的颜色,只有android:color一个属性

  android:color 填充的颜色
  padding: 设置内容与形状边界的内间距,可分别设置左右上下的距离

  一: 

    rectangle:

        

  • solid: 设置形状填充的颜色,只有android:color一个属性

    • android:color 填充的颜色
  • padding: 设置内容与形状边界的内间距,可分别设置左右上下的距离

    • android:left 左内间距
    • android:right 右内间距
    • android:top 上内间距
    • android:bottom 下内间距
  • gradient: 设置形状的渐变颜色,可以是线性渐变、辐射渐变、扫描性渐变

    • android:type 渐变的类型

      • linear 线性渐变,默认的渐变类型
      • radial 放射渐变,设置该项时,android:gradientRadius也必须设置
      • sweep 扫描性渐变
    • android:startColor 渐变开始的颜色
    • android:endColor 渐变结束的颜色
    • android:centerColor 渐变中间的颜色
    • android:angle 渐变的角度,线性渐变时才有效,必须是45的倍数,0表示从左到右,90表示从下到上
    • android:centerX 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
    • android:centerY 渐变中心的相对X坐标,放射渐变时才有效,在0.0到1.0之间,默认为0.5,表示在正中间
    • android:gradientRadius 渐变的半径,只有渐变类型为radial时才使用
    • android:useLevel 如果为true,则可在LevelListDrawable中使用
  • corners: 设置圆角,只适用于rectangle类型,可分别设置四个角不同半径的圆角,当设置的圆角半径很大时,比如200dp,就可变成弧形边了

    • android:radius 圆角半径,会被下面每个特定的圆角属性重写
    • android:topLeftRadius 左上角的半径
    • android:topRightRadius 右上角的半径
    • android:bottomLeftRadius 左下角的半径
    • android:bottomRightRadius 右下角的半径
  • stroke: 设置描边,可描成实线或虚线。

    • android:color 描边的颜色
    • android:width 描边的宽度
    • android:dashWidth 设置虚线时的横线长度
    • android:dashGap 设置虚线时的横线之间的距离
    • |

      二:oval oval用来画椭圆,而在实际应用中,更多是画正圆,比如消息提示,圆形按钮等

    • size: 设置形状默认的大小,可设置宽度和高度
      • android:width 宽度
      • android:height 高度
    • 下面是例子:
    • <?xml version="1.0" encoding="utf-8"?>
      <!-- android:shape指定形状类型,默认为rectangle -->
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="oval">
      <!-- padding设置内间距 -->
      <padding
      android:bottom="4dp"
      android:left="4dp"
      android:right="4dp"
      android:top="4dp" />
      <!-- size设置形状的大小 -->
      <size
      android:width="40dp"
      android:height="40dp" />
      <!-- gradient设置渐变 -->
      <gradient
      android:endColor="#000000"
      android:gradientRadius="40dp"
      android:startColor="#FFFFFF"
      android:type="radial" />
      </shape>
    • 引用的代码:
      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:layout_margin="8dp"
      android:text="6"
      android:textSize="20sp"
      android:textColor="@android:color/black"
      android:background="@drawable/bg_oval_with_gradient" />

      三: line   line主要用于画分割线,是通过stroke和size特性组合来实现的,先看虚线的代码:

    • <?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="#2F90BD"
      android:dashGap="2dp"
      android:dashWidth="4dp" /> 有dashwidth 和 dashgap 表示的虚线
      <!-- 形状的高度 -->
      <size android:height="4dp" />
      </shape>

      画线时,有几点特性必须要知道的:

      1. 只能画水平线,画不了竖线;
      2. 线的高度是通过stroke的android:width属性设置的;
      3. size的android:height属性定义的是整个形状区域的高度;
      4. size的height必须大于stroke的width,否则,线无法显示;
      5. 线在整个形状区域中是居中显示的;
      6. 线左右两边会留有空白间距,线越粗,空白越大;
      7. 引用虚线的view需要添加属性android:layerType,值设为"software",否则显示不了虚线。

      四: ring  圆 

    • 首先,shape根元素有些属性只适用于ring类型,先过目下这些属性吧:

      • android:innerRadius 内环的半径
      • android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,默认为3,表示内环半径为环的宽度除以3,该值会被android:innerRadius覆盖
      • android:thickness 环的厚度
      • android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,默认为9,表示环的厚度为环的宽度除以9,该值会被android:thickness覆盖
      • android:useLevel 一般为false,否则可能环形无法显示,只有作为LevelListDrawable使用时才设为true
    •  
    •   <gradient  />   -->渐变色
    •       < stroke   width="1dp" color="@android:color/black"/>   --> 边框的颜色 宽度

    如果想让ring 转起来   那么在外边加上一层 rotate就行了

    

<ProgressBar
android:layout_width="100dp"
android:layout_height="100dp"
android:indeterminateDrawable="@drawable/rotate_shape" />

android shape详解的更多相关文章

  1. Android Shape 详解

    1 http://blog.csdn.net/feng88724/article/details/6398193 2 <shape xmlns:android="http://sche ...

  2. [整理]Selector、shape详解

    Selector.shape详解(一) Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> ...

  3. Selector、shape详解,注意这两种图像资源都以XML方式存放在drawable不带分辨率的文件夹中

    Selector.shape详解(一) Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> ...

  4. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  5. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  6. Android ActionBar详解

    Android ActionBar详解 分类: Android2014-04-30 15:23 1094人阅读 评论(0) 收藏 举报 androidActionBar   目录(?)[+]   第4 ...

  7. Android 签名详解

    Android 签名详解 AndroidOPhoneAnt设计模式Eclipse  在Android 系统中,所有安装 到 系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程 ...

  8. Android编译系统详解(一)

    ++++++++++++++++++++++++++++++++++++++++++ 本文系本站原创,欢迎转载! 转载请注明出处: http://blog.csdn.net/mr_raptor/art ...

  9. Android布局详解之一:FrameLayout

      原创文章,如有转载,请注明出处:http://blog.csdn.net/yihui823/article/details/6702273 FrameLayout是最简单的布局了.所有放在布局里的 ...

随机推荐

  1. Python Paramiko模块安装和使用

    1.简介 大家会发现,常见的解决方法都会需要对远程服务器必要的配置,如果远程服务器只有一两台还好说,如果有N台,还需要逐台进行配置,或者需要使用代码进行以上操作时,上面的办法就不太方便了. 使用par ...

  2. SciTE 文本编辑器

    个人一直使用,强大,轻型基于 Scintilla. http://www.scintilla.org/SciTEDownload.html 解压缩后,能右键文件打开 修改注册表, 使能资源管理器 右键 ...

  3. phalcon count统计

    单表count: //How many robots are there? $number = Robots::count(); echo "There are ", $numbe ...

  4. 将cantk runtime嵌入到现有的APP中

    1,先取cantk-runtime-demos到本地: git clone https://github.com/drawapp8/cantk-runtime-demos 2,创建一个Android ...

  5. 【BZOJ 3295】动态逆序对 - 分块+树状数组

    题目描述 给定一个1~n的序列,然后m次删除元素,每次删除之前询问逆序对的个数. 分析:分块+树状数组 (PS:本题的CDQ分治解法见下一篇) 首先将序列分成T块,每一块开一个树状数组,并且先把最初的 ...

  6. 最最最简单的轮播图(JQuery)

    html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  7. backbone--部分总结

    1.Backbone.history.start 方法可以让我们在点击后退或者前进的时候同样会触发路由的事件. 2.添加路由的路径,添加的路由路径要求重写父类的routes这个对象 var CustR ...

  8. 初学Java之Pattern与Matcher类

    import java.util.regex.*; public class Gxjun{ public static void main(String args[]) { Pattern p; // ...

  9. jquery 实现 点击按钮后倒计时效果,多用于实现发送手机验证码、邮箱验证码

    原文链接:http://www.cnblogs.com/steed-zgf/archive/2012/02/03/2336984.html <!DOCTYPE html PUBLIC " ...

  10. 201. Bitwise AND of Numbers Range -- 连续整数按位与的和

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...