[英]Drawing Between Two Points on an Android Emulator in Java
Given two points on an emulator (x and y values for both coordinates), how do I draw a line connecting them?给定模拟器上的两个点(两个坐标的 x 和 y 值),如何绘制连接它们的线?
I have already retrieved the two coordinates like this...我已经像这样检索了两个坐标......
//imports not included
ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(iv.getLayoutParams());
float fx = event.getX();
float fy = event.getY();
int x = (int)fx;
int y = (int)fy;
Use Canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
method to draw a straight line between two points using X, Y coordinates like the following Code Snippet.使用
Canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
方法使用 X、Y 坐标在两点之间绘制一条直线,如下面的代码片段。
Canvas canvas = new Canvas(bitmap);
Canvas canvas = new Canvas(位图);
Paint paint = new Paint();
油漆油漆=新油漆();
paint.setStrokeWidth(5);
Paint.setStrokeWidth(5);
paint.setColor(Color.Black);
Paint.setColor(Color.Black);
paint.setStyle(Paint.Style.STROKE);
Paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
Paint.setAntiAlias(true);
Canvas.drawLine(startX, startY, stopX, stopY, paint);
Canvas.drawLine(startX, startY, stopX, stopY, Paint);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.