Android Shape 形状
Shape继承体系:
Shape (android.graphics.drawable.shapes)
----PathShape (android.graphics.drawable.shapes)
----RectShape (android.graphics.drawable.shapes)
--------ArcShape (android.graphics.drawable.shapes)
--------OvalShape (android.graphics.drawable.shapes)
--------RoundRectShape (android.graphics.drawable.shapes)
RectShape
RectShape rectShape = new RectShape();
ShapeDrawable drawable = new ShapeDrawable(rectShape);
drawable.getPaint().setColor(Color.RED);
drawable.getPaint().setStyle(Paint.Style.FILL); //填充
view.setBackgroundDrawable(drawable);
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="292" height="295" alt=""> 矩形
RoundRectShape
float[] outerRadii = {20, 20, 40, 40, 60, 60, 80, 80};//外矩形 左上、右上、右下、左下 圆角半径
//float[] outerRadii = {20, 20, 20, 20, 20, 20, 20, 20};//外矩形 左上、右上、右下、左下 圆角半径
RectF inset = new RectF(100, 100, 200, 200);//内矩形距外矩形,左上角x,y距离。 右下角x,y距离
float[] innerRadii = {20, 20, 20, 20, 20, 20, 20, 20};//内矩形 圆角半径
//RoundRectShape roundRectShape = new RoundRectShape(outerRadii, inset, innerRadii);
RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, innerRadii); //无内矩形 ShapeDrawable drawable = new ShapeDrawable(roundRectShape);
drawable.getPaint().setColor(Color.MAGENTA);
drawable.getPaint().setAntiAlias(true);
drawable.getPaint().setStyle(Paint.Style.STROKE);//描边
view.setBackground(drawable);
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="297" height="299" alt=""> 无内矩形的圆角矩形 带内矩形的圆角矩形
OvalShape
OvalShape ovalShape = new OvalShape();
ShapeDrawable drawable = new ShapeDrawable(ovalShape);
drawable.getPaint().setColor(Color.RED);
drawable.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
view.setBackgroundDrawable(drawable);
椭圆。 而当View的宽高相等时,就绘出了圆
ArcShape
ArcShape arcShape = new ArcShape(45, 270); //顺时针 開始角度45。 扫描的角度270 扇形
ShapeDrawable drawable = new ShapeDrawable(arcShape);
drawable.getPaint().setColor(Color.RED);
drawable.getPaint().setStyle(Paint.Style.FILL); // Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.aa)).getBitmap();
// BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader
// .TileMode.REPEAT);
// Matrix matrix = new Matrix();
// matrix.preScale(600.00f / bitmap.getWidth(), 600.00f / bitmap.getHeight());//view:w=600,h=600
// bitmapShader.setLocalMatrix(matrix);
// drawable.getPaint().setShader(bitmapShader); view.setBackgroundDrawable(drawable);
扇形图
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="353" height="415" alt=""> 结合BitmapShader
PathShape
Path path = new Path();
path.moveTo(50, 0);
path.lineTo(0, 50);
path.lineTo(50, 100);
path.lineTo(100, 50);
path.lineTo(50, 0);
PathShape pathShape = new PathShape(path, 200, 100);
ShapeDrawable drawable = new ShapeDrawable(pathShape);
drawable.getPaint().setColor(Color.RED);
drawable.getPaint().setStyle(Paint.Style.FILL);
imageView.setBackgroundDrawable(drawable);
以Path路径对象,来设定图形。
PathShape的构造函数:PathShape(path, stdWidth, stdHeight);
stdWidth:标准宽度
stdHeight:标准高度
在构造PathShape对象时,设置了宽高的标准。
内部函数
protected void onResize(float width, float height) {
mScaleX = width / mStdWidth;
mScaleY = height / mStdHeight;
} public void draw(Canvas canvas, Paint paint) {
canvas.save();
canvas.scale(mScaleX, mScaleY);
canvas.drawPath(mPath, paint);
canvas.restore();
}
Shape基类中有函数 resize(),当中调用了onResize()。ShapeDrawable中会调用resize()。
有了设定的标准宽高。再算出实际宽高与标准宽高的比率,最后在绘制时,画布canvas缩放。
造成的效果: path中的(x,y)坐标值 乘以 比率值,即是 终于呈现出的坐标值(实际内部是缩放的canvas)
比方,这里view的 w=400。 h=400
假设标准宽高都等于400,那么canvas终于不缩放,即1:1。
PathShape pathShape = new PathShape(path, 400, 400);
stdx=400, stdy=400
PathShape pathShape = new PathShape(path, 100, 100);
stdx=100, stdy=100
PathShape pathShape = new PathShape(path, 200, 100);
stdx=200, stdy=100
Android Shape 形状的更多相关文章
- Android shape自定义形状,设置渐变色
<?xml version="1.0" encoding="utf-8"?> <!-- android:shape=["rect ...
- android:shape
android:shape=["rectangle" | "oval" | "line" | "ring"] shape ...
- android shape详解
shape--> shape属性: rectangle: 矩形,默认的形状,可以画出直角矩形.圆角矩形.弧形等 solid: 设置形状填充的颜色,只有android:color一个属性 andr ...
- android shape(如自定义Button)
Shape 前言:有时候会去自己去画一些Button的样式来展现在UI当中,其中主要用到的就是Shape 先来看一段代码: <?xml version="1.0" encod ...
- Android 之形状Drawable
形状Drawable资源允许使用 <shape>标记指定基本形状的尺寸.背景.轮廓线,从而定义这些基本形状. 每个形状都包含一个类型(通过shape属性指定).定义该形状尺寸的属性,以及指 ...
- android shape 大全 (转)
1. 各属性的配置语法 在项目 res/drawable 文件夹中创建一个以 shape 为根节点的 XML 文件,基本语法如下: <?xml version="1.0" e ...
- android:shape属性详解
这一类的shape定义在xml中 file location: res/drawable/filename.xml The filename is used as the resource ID.(这 ...
- Android——shape和selector和layer-list的(详细说明 转)
<shape>和<selector>在Android UI设计中经常用到.比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到<shape> ...
- android shape.xml 属性详解
转载源:http://blog.csdn.net/harvic880925/article/details/41850723 一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标 ...
随机推荐
- android基础学习-Fragment和eclipse快捷键
使用Fragment的原因 1. Activity间的切换不流畅 2. 模块化Activity,方便做局部动画(有时为了到达这一点要把多个布局放到一个activity里面,现在可以用多Fragment ...
- Android中各级目录的作用
Android中各级目录的作用 一.目录结构 src目录---存放源代码文件 gen目录---ADT插件生成的文件,(自动生成) R.java文件 drawable类---给图片生产的ID ...
- 解决sqoop报错Invalid number; item = ITEM_UNICODE
报错栈: java.sql.SQLException: Invalid number; item = ITEM_UNICODE at com.intersys.jdbc.SysList.getInt( ...
- mysql concat函数进行模糊查询
concat() 函数,是用来连接字符串. 精确查询: select * from user where name=”zhangsan” 模糊查询: select * from user where ...
- iOS: 如何调节UITabbarItem的图片和文字位置
转载自:http://blog.csdn.net/kevinwlc/article/details/21467499/ 在ios7中,方法setFinishedSelectedImage:withFi ...
- RS报内存错误XQE-ROL-0183
描述问题:RS开发了一个报表,里面涉及日期维度精细判断,还有FM里面做的权限处理,处理逻辑可能比较复杂,后面又加了一个case when的数据项结果就出现了下面的错误 下面就说一下处理方案 从字面意思 ...
- 介绍Visual Studio的Android模拟器
介绍Visual Studio的Android模拟器 http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/introducing-vi ...
- Servlet对文件的读写操作
(1)怎样在serlvet中读取文件的内容 package com.tsinghua; import java.io.*; import javax.servlet.http.*; public cl ...
- JavaScript计算两个日期的时间差
/** * * @param startTime * @param endTime * @param diffType * @returns {Number|number} * @constructo ...
- 【pyhon】理想论坛单帖爬虫取得信息存入MySql数据库
代码: # 单帖爬虫,用于爬取理想论坛单个帖子得到发帖人,发帖时间和回帖时间并存入数据库,url例子见main函数 from bs4 import BeautifulSoup import reque ...