[Android] Drawable总结(一)
来源:互联网 发布:数据质量评估报告 编辑:程序博客网 时间:2024/05/20 15:40
前言
最近看了一遍Android中的Drawable,因为Drawable的分类很多,而且Drawable在UI方面的开发工作中显的尤为重要,因为我在这里对Drawable做个总结。
BitmapDrawable
语法:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@[package:]drawable/drawable_resource" android:antialias=["true" | "false"] android:dither=["true" | "false"] android:filter=["true" | "false"] android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" | "fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" | "fill" | "clip_vertical" | "clip_horizontal"] android:mipMap=["true" | "false"] android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />
属性解释:
android:src 这个比较简单,就是图片的资源id
android:antialisa: 这个是图片是否抗锯齿
anroid:dither 是否开启抖动效果 ,默认是开启的
android:filter 图片是否开启过滤效果,如果开启,则在图片的宽高发生变化时,显示效果会比较好,默认是开启状态
android:gravity 可以对图片进行定位,当然前提是图片小于所在容器的大小。
android:mipMap 开发中不常用,可以不看
android:tileMode 平铺模式,这个选项有四个值分别是 disabled,clamp,repeat,mirror。
disabled是默认值,关闭平铺;
clamp的话,图片会进行扩展到周围的区域;
repeat的话,就是图片会进行重复的显示;
mirror其实就是一个图片在镜子当中的显示效果。
<?xml version="1.0" encoding="utf-8"?><bitmap android:src="@drawable/ad3" android:antialias="true" android:dither="true" android:filter="true" android:tileMode="mirror" xmlns:android="http://schemas.android.com/apk/res/android"/>
效果:
repeat
clamp
mirror
ShapeDrawable
语法:
<?xml version="1.0" encoding="utf-8"?><scalexmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@drawable/drawable_resource"android:scaleGravity=["top" | "bottom" | "left" | "right" | "center_vertical" | "fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" | "fill" | "clip_vertical" | "clip_horizontal"]android:scaleHeight="percentage"android:scaleWidth="percentage" />
属性解释:
android:shape 这个是定义图形要显示的形状,有四个,分别是 rectangle(矩形),oval(椭圆),line(线性),ring(环形)。
表示shape的四个角的角度
android:radius 为四个角同时设定相同角度。
android:topLeftRadius 设定左上角的角度
android:topRightRadius设定右上角的角度。
android:bottomLeftRadius设定左下角的角度。
android:bottomRightRadiys 设定右下角的角度。
主要是设置颜色变化的梯度即渐变的效果。
android:angle 渐变的角度
android:centerX ,android:centerY渐变的中心点的横坐标和纵坐标。值为0~1之间
android:startColor 渐变的初始颜色
android:endColor渐变的结束色
android:gradientRadius 渐变的半径
android:type 渐变的类型,有linear、radial、sweep三种
表示纯色的填充,通过android:color指定颜色
android:width 周边一个圆圈的宽度
android:color 描边的颜色
android:dashWidth 虚线的每个小线段的长度
android:dashGap 圆形虚线每个小线段的空隙间隔
View 中的drawable相对于View的间隔。
用于指定shape的宽度和高度
例子:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /></shape>
效果:
LayerDrawable
语法:
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@[package:]drawable/drawable_resource" android:id="@[+][package:]id/resource_name" android:top="dimension" android:right="dimension" android:bottom="dimension" android:left="dimension" /></layer-list>
例子:
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:src="@drawable/android_red" android:gravity="center" /> </item> <item android:top="10dp" android:left="10dp"> <bitmap android:src="@drawable/android_green" android:gravity="center" /> </item> <item android:top="20dp" android:left="20dp"> <bitmap android:src="@drawable/android_blue" android:gravity="center" /> </item></layer-list>
效果:
对应的标签是表示叠加的多个Drawable。
参考文献
《Android 开发艺术探索》
- [Android] Drawable总结(一)
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android Drawable Resource学习(一)、Drawable Resource简介
- Android画图学习总结(一)——Android Drawable、Bitmap、Canvas和Paint的区别
- android drawable源码解析(一)
- Android学习之Drawable(一)
- 领略千变万化的Android Drawable (一)
- 领略千变万化的Android Drawable (一)
- Android资源之Drawable介绍(一)
- 领略千变万化的Android Drawable (一)
- Android的Drawable学习(一)
- android Drawable 学习总结
- Android Drawable总结
- 使用DFSClient实现 hadoop上传文件功能,采用使用输入输出流实现 Hadoop 版本2.7.0
- js身份验证
- 第K个排列组合
- android系统常用adb命令整理
- Robot Framwork问题和解决方法
- [Android] Drawable总结(一)
- css中!important的用法
- 开发者所需要知道的 iOS 10 SDK 新特性
- HDU 4969 (微积分)
- Appium+Robotframework实现iOS应用的自动化测试-6:手势密码的解决方案
- [Leetcode]203. Remove Linked List Elements
- ORACLE---索引
- README.md文件 github Markdown语言详解 md文件用法和说明
- Spring事务管理