
private voID drawovalAndArrow(Canvas canvas){ Paint circlePaint = new Paint(); circlePaint.setStyle(Paint.Style.FILL_AND_stroke); circlePaint.setAntiAlias(true); circlePaint.setstrokeWIDth(2); circlePaint.setcolor(color.CYAN); float centerWIDth = canvas.getWIDth()/2; //get center x of display float centerHeight = canvas.getHeight()/2; //get center y of display float circleRadius = 20; //set radius float circledistance = 200; //set distance between both circles //draw circles canvas.drawCircle(centerWIDth,centerHeight,circleRadius,circlePaint); canvas.drawCircle(centerWIDth+circledistance,circlePaint); //to draw an arrow,just lines needed,so style is only stroke circlePaint.setStyle(Paint.Style.stroke); circlePaint.setcolor(color.RED); //create a path to draw on Path arrowPath = new Path(); //create an invisible oval. the oval is for "behind the scenes",to set the path´ //area. Imagine this is an egg behind your circles. the circles are in the mIDdle of this egg final RectF arrowoval = new RectF(); arrowoval.set(centerWIDth,centerHeight-80,centerWIDth + circledistance,centerHeight+80); //add the oval to path arrowPath.addArc(arrowoval,-180,180); //draw path on canvas canvas.drawPath(arrowPath,circlePaint); //draw arrowhead on path start arrowPath.moveto(centerWIDth,centerHeight ); //move to the center of first circle arrowPath.lineto(centerWIDth-circleRadius,centerHeight-circleRadius);//draw the first arrowhead line to the left arrowPath.moveto(centerWIDth,centerHeight );//move back to the center arrowPath.lineto(centerWIDth+circleRadius,centerHeight-circleRadius);//draw the next arrowhead line to the right //same as above on path end arrowPath.moveto(centerWIDth+circledistance,centerHeight ); arrowPath.lineto((centerWIDth+circledistance)-circleRadius,centerHeight-circleRadius); arrowPath.moveto(centerWIDth+circledistance,centerHeight ); arrowPath.lineto((centerWIDth+circledistance)+circleRadius,centerHeight-circleRadius); //draw the path canvas.drawPath(arrowPath,circlePaint);} 此外,这将找到屏幕的两侧(横向模式),并将在屏幕上绘制完美的曲线
protected voID onDraw(Canvas canvas) { super.onDraw(canvas); PointF mPoint1 = new PointF(w/1.2F,h/1.2F); PointF mPoint2 = new PointF(w/24,h/1.2F); Path myPath1 = new Path(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Style.stroke); paint.setstrokeWIDth(2); paint.setcolor(color.WHITE); myPath1 = drawCurve(canvas,paint,mPoint1,mPoint2); canvas.drawPath(myPath1,paint);}private Path drawCurve(Canvas canvas,Paint paint,PointF mPointa,PointF mPointb) { Path myPath = new Path(); myPath.moveto(63*w/64,h/10); myPath.quadTo(mPointa.x,mPointa.y,mPointb.x,mPointb.y); return myPath; } 在androID中绘画的有用参考:
How to draw Arcs in Android using canvas?
Basic Painting with Views
总结以上是内存溢出为你收集整理的如何在android中绘制曲线?全部内容,希望文章能够帮你解决如何在android中绘制曲线?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)