Stbdroid之ShapeDrawable
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的更多相关文章
- Android ShapeDrawable
今天做项目碰到一个这样的情况,就是颜色指示框,用的是正方形边框是黑色的,里面填充颜色,颜色值是动态的,为了解决这个问题,查了好多资料,终于找到解决的方法,利用ShapeDrawable,我们自定义一个 ...
- Android ShapeDrawable无法上色
在Android中的View设置背景时,使用ShapeDrawable有可能出现无法上色的问题(最终背景为黑色),例如,使用如下的代码为控件设置颜色时,控件背景将会变成黑色 ShapeDrawable ...
- android学习笔记33——资源ShapeDrawable
ShapeDrawable ShapeDrawable用于定义一个基本的几何图像(如,矩形.圆形.线条.......). 定义ShapeDrawable的XML文件的根元素是<shape.../ ...
- ShapeDrawable 资源
ShapeDrawable 用于定义一个基本的几何图形(如矩形.圆形.线条等),定义 ShapeDrawable 的 XML 文件的根元素是<shape.../>元素,该元素可指定如下属性 ...
- 使用(Drawable)资源———ShapeDrawable资源
ShapeDrawable用于定义一个基本的几何图形(如矩形.圆形.线条等),定义ShapeDrawable的XML文件的根元素是<shape.../>元素,该元素可指定如下属性. and ...
- 安卓自定义控件(二)BitmapShader、ShapeDrawable、Shape
第一篇博客中,我已经Canvas.Paint.Shader.Xfermode这些对象做了总结,而现在这篇文章主要介绍BitmapShader位图渲染,Xfermode如何实际应用,还有形状的绘制.不过 ...
- ShapeDrawable做放大镜效果
引用一下ShapeDrawable的类的说明: java.lang.Object ? android.graphics.drawable.Drawable ? android.grap ...
- Android ShapeDrawable之OvalShape、RectShape、PaintDrawable、ArcShape
Android ShapeDrawable之OvalShape.RectShape.PaintDrawable.ArcShape Android图形图像基础之OvalShape.RectShap ...
- 关于ShapeDrawable应用的一些介绍(中)之Gradient
版权声明:本文为博主原创文章,未经博主允许不得转载. Gradient,渐变,是在界面设计中最经常用到的一种技巧,只要涉及到颜色的处理,浓妆淡抹总相宜,说的就是它. 在Android中,当然也提供了这 ...
随机推荐
- Qt窗口屏幕居中显示(有专门的QDesktopWidget,先计算后显示)
窗口的屏幕居中显示问题,在各开发工具中原理相同,首先使用特定的方法得到显示屏幕的宽度和高度,再根据窗口本身的宽度和高度计算出窗口的左上角坐标位置. Qt中可以采用两种方法达到窗口的屏幕居中显示: 方法 ...
- lambda表达式和闭包
lambda表达式和闭包 熟悉的Javascript或者Ruby的同学,可能对另一个名词:闭包更加熟悉.因为一般闭包的示例代码,长得跟lambda差不多,导致我也在以前很长一段时间对这两个概念傻傻分不 ...
- android下tcpdump抓包
tcpdump是最快捷方便的抓包方式,还可以加深对网络协议的理解.android下可以通过如下方式抓包: 1 Android上启动tcpdump Android设备可以把tcpdump的可执行文件上传 ...
- Python BeautifulSoup4 使用指南
前言: 昨天把传说中的BeautifulSoup4装上了,还没有装好的童鞋,请看本人的上一篇博客: Python3 Win7安装 BeautifulSoup,依照里面简单的步骤就能够把Beautifu ...
- 设置android:supportsRtl="true"无效问题
今天解bug时,遇到这样一个问题: 问题描写叙述:切换系统语言为阿拉伯文时,actionbar布局没有变为从右向左排列. 于是,我在Androidmanifest.xml文件里的 appli ...
- 最近adt升级引起的问题
其实也不知道是什么原因引起的,因为 之前安装的adt就是23.0.3的版本,但是最近突然创建安卓工程时出现了如下问题 D:\workspace\appcompat_v7\res\values-v21\ ...
- 从零开始写驱动——vfd专用驱动芯片HT16514并行驱动程序编写
前言 一直看别人搞的 vfd 很漂亮,前段时间淘了个 vfd 模块来,但没有模块资料,还好芯片没有打磨的,良心商家啊.周末抽空来研究一下这个东西. 从零开始 打开外壳 测试线路 查看芯片是 HT165 ...
- BestCoder Round #47
1001 Senior's Array 题目链接:1001 题意:给你一个长度为n的序列,你必须修改序列中的某个数为P,求修改后的最大连续子序列和. 思路:数据量比较小,可以直接暴力做, 枚举序列的每 ...
- Mac OS X 下 TAR.GZ 方式安装 MySQL 5.7+
方法: http://www.widlabs.com/article/mac-os-x-install-mysql-57-with-tar-gz mysql下载地址:http://www.mysq ...
- python 10 min系列三之小爬虫(一)
python10min系列之小爬虫 前一篇可视化大家表示有点难,写点简单的把,比如命令行里看论坛的十大,大家也可以扩展为抓博客园的首页文章 本文原创,同步发布在我的github上 据说去github右 ...