Android编程绘图操作之弧形绘制方法示例
程序员文章站
2023-12-02 18:36:22
本文实例讲述了android编程绘图操作之弧形绘制方法。分享给大家供大家参考,具体如下:
/**
* 绘制弧形图案
* @description:
*...
本文实例讲述了android编程绘图操作之弧形绘制方法。分享给大家供大家参考,具体如下:
/** * 绘制弧形图案 * @description: * @author ldm * @date 2016-4-25 下午4:37:01 */ public class arcsactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(new sampleview(this)); } /** * 自定义绘制图案的view * * @description: * @author ldm * @date 2016-4-25 下午4:19:40 */ private static class sampleview extends view { // 画圆形图案的画笔数组 private paint[] mpaints; // 画矩形的画笔 private paint mframepaint; // 是否以矩形中心画图 private boolean[] musecenters; // 矩形框数组 private rectf[] movals; // 上面较大的矩形框 private rectf mbigoval; // 画圆弧起点 private float mstart; // 画圆弧角度 private float msweep; // 画大图形对应角标index private int mbigindex; // 角度变化增量 private static final float angle_step = 3; // 初始角度 private static final float start_angle = 15; public sampleview(context context) { super(context); mpaints = new paint[4]; musecenters = new boolean[4]; movals = new rectf[4]; mpaints[0] = new paint(); mpaints[0].setantialias(true);// 设置抗紧钜齿 mpaints[0].setstyle(paint.style.fill);// 设置画笔填充风格 mpaints[0].setcolor(0x88ff0000);// 设置颜色 musecenters[0] = false; mpaints[1] = new paint(mpaints[0]); mpaints[1].setcolor(0x8800ff00); musecenters[1] = true; mpaints[2] = new paint(mpaints[0]); mpaints[2].setstyle(paint.style.stroke);// 设置画笔空心风格 mpaints[2].setstrokewidth(4);// 设置画笔宽度 mpaints[2].setcolor(0x880000ff);// 设置颜色 musecenters[2] = false; mpaints[3] = new paint(mpaints[2]); mpaints[3].setcolor(0x88888888); musecenters[3] = true; mbigoval = new rectf(40, 10, 280, 250);// 初始化较大的矩形 movals[0] = new rectf(10, 270, 70, 330);// 初始化4个较小矩形 movals[1] = new rectf(90, 270, 150, 330); movals[2] = new rectf(170, 270, 230, 330); movals[3] = new rectf(250, 270, 310, 330); mframepaint = new paint(); mframepaint.setantialias(true); mframepaint.setstyle(paint.style.stroke); mframepaint.setstrokewidth(0); } @override protected void ondraw(canvas canvas) { canvas.drawcolor(color.white); // 画大矩形 canvas.drawrect(mbigoval, mframepaint); // 在大矩形分别 画4个圆弧图形 canvas.drawarc(mbigoval, mstart, msweep, musecenters[mbigindex], mpaints[mbigindex]); for (int i = 0; i < 4; i++) { canvas.drawrect(movals[i], mframepaint);// 画四个小矩形 canvas.drawarc(movals[i], mstart, msweep, musecenters[i],// 在四个小矩形中分别画圆弧 mpaints[i]); } msweep += angle_step;// 弧度改变 if (msweep > 360) {// 弧度控制 msweep -= 360; mstart += start_angle; if (mstart >= 360) { mstart -= 360; } mbigindex = (mbigindex + 1) % movals.length; } invalidate(); } } }
静态效果如图:
更多关于android相关内容感兴趣的读者可查看本站专题:《android图形与图像处理技巧总结》、《android开发入门与进阶教程》、《android调试技巧与常见问题解决方法汇总》、《android基本组件用法总结》、《android视图view技巧总结》、《android布局layout技巧总结》及《android控件用法总结》
希望本文所述对大家android程序设计有所帮助。