安卓xml绘图
来源:互联网 发布:网络暴力乔任梁 编辑:程序博客网 时间:2024/06/05 08:58
xml在安卓中除了作为布局文件和配置文件外,还能辅助我们绘图。下面我们来看一下xml在这方面的应用。
1.Bitmap
使用Bitmap引用图片,可直接将图片转成Bitmap在程序中使用。
<?xml version="1.0" encoding="utf-8"?><bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ic_launcher"> </bitmap>
2.Shape
使用shape可在xml中绘制各种形状。以下列出了shape的所有用途。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle"|"oval"|"line"|"ring"]> <!-- 使用shape为rectangle时配置corner --> <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="color" android:endColor="color" android:startColor="color" android:gradientRadius="integer" android:useLevel=["ture"|"false"] android:type=["linear"|"radial"|"sweep"] /> <!-- 内边距 --> <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> <!-- 指定大小,一般用在imageView配合scaleType属性使用 --> <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>3.Layer
Layer类似ps中的图层的概念,可实现图像叠加的效果。
用法如下:
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 图片1 --> <item android:drawable="@drawable/ic_launcher"/> <!-- 图片 --> <item android:drawable="@drawable/ic_launcher" android:left="10dip" android:top="10dip" android:right="10dip" android:bottom="10dip" /></layer-list>
selector用于实现静态绘图中的事件反馈。例如点击获得焦点时图片反白效果。也可通过点击事件设置不同的图片。
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 默认时的图片背景 --> <item android:drawable="@drawable/bitmap" /> <!-- 没有焦点时的图片背景 --> <item android:state_focused="false" android:drawable="@drawable/ic_launcher"/> <!-- 非触摸模式下获得焦点并单击时的背景图片 --> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/ic_launcher"/> <!-- 触摸模式下单击时的背景图片 --> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/ic_launcher"/> <!-- 选中时的背景图片 --> <item android:state_selected="true" android:drawable="@drawable/ic_launcher"/> <!-- 获得焦点时的背景图片 --> <item android:state_focused="true" android:drawable="@drawable/ic_launcher"/> </selector>
1 0
- 安卓xml绘图
- 安卓 bitmap绘图
- 安卓 View绘图笔记
- 安卓开发之绘图
- 安卓、Qt绘图坐标变换
- 安卓绘图之贝塞尔曲线
- k线图学习--安卓绘图基本知识
- 安卓canvas绘图,锯齿问题
- 安卓 三个绘图工具类详解
- XML-绘图
- 安卓xml解析
- 安卓反编译XML
- 解析 xml 安卓
- 安卓 解析xml
- 安卓xml解析
- Android绘图之XML绘图
- 安卓sax解析xml
- 安卓xml特殊字符
- 《JVM故障诊断指南》之4 —— Java 8:从持久代到metaspace
- $.extend()方法和(function($){...})(jQuery)详解
- fmt 国际化 日期 数字 本地环境 字符编码 本地资源
- Unity 射线检测碰撞
- vs2013更新了代码,但是运行没效果
- 安卓xml绘图
- Windows下Redis安装和使用
- FatMouse and Cheese
- Hibernate关联关系映射(双向篇)
- 用angularjs遇到的坑
- Python IO multiplex
- collectionView 的选中添加数组和再点击从数组中删除
- 使用子查询。所谓子查询就是嵌套在另外一个查询内部的查询。mysql
- 图像处理-cvCopy与cvCloneImage的区别