如何动态地画一条线在android系统 [英] How to draw a line dynamically in android
问题描述
可能重复:结果
如何绘制在android系统行
我有,因为我们用铅笔在比赛做列匹配两种选择。如果我在一列中单击某行,并与另一列则动态该行应两行之间划出其它合适的行匹配的行。首先,我去与拖放功能。但我不能画线dynamically.How这是可能的?请给我建议。
I have to match two options as we do in match the columns by using pencil. If i click a row in one column and match that row with other suitable row in other column then the line dynamically should be drawn between two rows. Firstly i went with drag and drop functionality. but with that i can not draw line dynamically.How that is possible? Please give me suggestions.
推荐答案
使用来自MapView的投影,以GeoPoints转换成屏幕之分。在此之后,您可以使用路径来绘制所需的行。第一点,应path.moveTo(X,Y),并用path.lineTo其余(X,Y)来指定。在最后你调用canvas.drawPath(路径)和你做。
Use the Projection from the MapView in order to convert GeoPoints to "screen" points. After that you can use Path to draw the line that you want. The first point should be specified with path.moveTo(x, y) and the rest with path.lineTo(x, y). At the end you call canvas.drawPath(path) and you are done.
下面是我的draw()方法绘制围绕一组点的多边形code。请注意,您不必使用path.close()像我一样在我的code。
Below is a code from my draw() method that draws a polygon around a set of points. Note that you do not have to use path.close() as I did on my code.
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
{
if(shadow){
if(isDrawing == false){
return;
}
Projection proj = mapView.getProjection();
boolean first = true;
/*Clear the old path at first*/
path.rewind();
/* The first tap */
Paint circlePaint = new Paint();
Point tempPoint = new Point();
for(GeoPoint point: polygon){
proj.toPixels(point, tempPoint);
if(first){
path.moveTo(tempPoint.x, tempPoint.y);
first = false;
circlePaint.setARGB(100, 255, 117, 0);
circlePaint.setAntiAlias(true);
canvas.drawCircle(tempPoint.x, tempPoint.y, FIRST_CIRCLE_RADIOUS, circlePaint);
}
else{
path.lineTo(tempPoint.x, tempPoint.y);
circlePaint.setARGB(100, 235, 0, 235);
circlePaint.setAntiAlias(true);
canvas.drawCircle(tempPoint.x, tempPoint.y, CIRCLE_RADIOUS, circlePaint);
}
}
/* If indeed is a polygon just close the perimeter */
if(polygon.size() > 2){
path.close();
}
canvas.drawPath(path, polygonPaint);
super.draw(canvas, mapView, shadow);
}
}
参见:<一href=\"http://stackoverflow.com/questions/7955411/dynamically-draw-lines-between-multiple-geopoints-in-android-mapview\">Dynamically在借鉴Android的图形页面多GeoPoints之间的界线
这篇关于如何动态地画一条线在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!