[英]Drawing Between Two Points on an Android Emulator in Java
給定模擬器上的兩個點(兩個坐標的 x 和 y 值),如何繪制連接它們的線?
我已經像這樣檢索了兩個坐標......
//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;
使用Canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
方法使用 X、Y 坐標在兩點之間繪制一條直線,如下面的代碼片段。
Canvas canvas = new Canvas(位圖);
油漆油漆=新油漆();
Paint.setStrokeWidth(5);
Paint.setColor(Color.Black);
Paint.setStyle(Paint.Style.STROKE);
Paint.setAntiAlias(true);
Canvas.drawLine(startX, startY, stopX, stopY, Paint);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.