android.graphics(一)shapes
来源:互联网 发布:提示mac中毒 mackeeper 编辑:程序博客网 时间:2024/06/03 19:54
先看下shapes的结构
PathShape extends ShapeRectShape extends ShapeArcShape extends RectShapeOvalShape extends RectShapeRoundRectShape extends RectShape
其中:
ArcShape:扇形;
OvalShape:椭圆形;
RoundRectShape :圆角矩形;
PathShape:指定曲线图形;
1、ArcShape
ArcShape(float startAngle, float sweepAngle)
startAngel
为直角坐标系中起始位置角度(如45,代表45°角位置)
sweepAngel
为起始位置和椭圆中心连线在直角坐标系中扫过的角度(如-135°,代表连线逆时针扫过135°角)
ArcShape arcShape = new ArcShape(30, 180); ShapeDrawable arcShapeDrawable = new ShapeDrawable(arcShape); //指定填充颜色 arcShapeDrawable.getPaint().setColor(Color.RED); // 指定填充模式FILL,STROKE,FILL_AND_STROKE arcShapeDrawable.getPaint().setStyle(Paint.Style.FILL); findViewById(R.id.textView1).setBackgroundDrawable(arcShapeDrawable);
2、OvalShape
OvalShape是指给定的矩形框的内切椭圆饼
OvalShape ovalShape = new OvalShape(); ShapeDrawable ovalShapeDrawable = new ShapeDrawable(ovalShape); ovalShapeDrawable.getPaint().setColor(Color.RED); ovalShapeDrawable.getPaint().setStyle(Paint.Style.FILL); findViewById(R.id.textView2).setBackgroundDrawable(ovalShapeDrawable);
3、RoundRectShape
RoundRectShape(float[] outerRadii, RectF inset,float[] innerRadii)
outerRadii:指定一个外部(圆角)矩形
inset:内部矩形与外部矩形的距离
innerRadii:一个可选的 内部(圆角)矩形
一个包含8个弧度值,指定外部圆角矩形的 4个角部的弧度
new float[] {l, l, t, t, r, r, b, b};参数: 12代表左上角, 34代表右上角, 56代表右下角, 78代表左下角,如果没弧度的话,传入null即可。
// 外部矩形弧度float[] outerRadii = new float[]{8, 8, 8, 8, 8, 8, 8, 8};// 内部矩形与外部矩形的距离RectF inset = new RectF(50, 20, 50, 50);// 内部矩形弧度float[] innerRadii = new float[]{20, 20, 20, 20, 20, 20, 20, 20};RoundRectShape roundRectShape = new RoundRectShape(outerRadii, inset, innerRadii);ShapeDrawable roundRectShapeDrawable = new ShapeDrawable(roundRectShape); roundRectShapeDrawable.getPaint().setColor(Color.RED); roundRectShapeDrawable.getPaint().setStyle(Paint.Style.FILL); findViewById(R.id.textView3).setBackgroundDrawable(roundRectShapeDrawable);
4、PathShape
路径绘图
PathShape(Path path, float stdWidth, float stdHeight)
stdWidth:标准宽度
stdHeight:标准高度
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); findViewById(R.id.textView4).setBackgroundDrawable(drawable);
参考:
http://blog.csdn.net/vqqyuan/article/details/42921315
http://blog.csdn.net/zhangphil/article/details/52025152
http://blog.csdn.net/silk2018/article/details/19192329
http://blog.csdn.net/jjwwmlp456/article/details/46928859
阅读全文
0 0
- android.graphics(一)shapes
- android.graphics.drawable.shapes
- android绘制图形:android.graphics.drawable.shapes
- android Graphics(一):Path
- Android 2D Graphics学习(一)、android.graphics介绍
- Android 2D Graphics学习(一)、android.graphics介绍
- Android 2D Graphics学习(一)、android.graphics介绍
- android.graphics.Bitmap 一
- android.graphics一、概述
- Android Graphics (一) :Paint
- android.graphics(三)graphics
- Displaying Graphics with OpenGL ES(二)——定义形状Defining Shapes
- Displaying Graphics with OpenGL ES(三)——Drawing Shapes
- Android ApiDemo 笔记(一)Content与Graphics
- Android ApiDemo 笔记(一)Content与Graphics
- Android ApiDemo 笔记(一)Content与Graphics
- Android ApiDemo 笔记(一)Content与Graphics
- android Graphics(一):概述及基本几何图形绘制
- ios-AVPlayerViewController简单使用
- spring boot 一体化,想上线,一个jar包就够了。(h2 web 数据库访问)
- ubuntu kylin 下使用Anaconda
- MyBatis批量增加
- 基于g-sensor的起立坐下的的识别
- android.graphics(一)shapes
- MySql的增删改查
- 最经典的黑客技术入门知识
- Maximum Value Problem FZU
- Java语言基础
- QT5显示中文
- JBPM与Spring整合
- day15笔记
- php面向对象之类的创建