2

Possible Duplicate:
How to draw a line in android

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.

Community
  • 1
  • 1
Naina
  • 211
  • 1
  • 4
  • 14

3 Answers3

2

Get the Touch Events for both the row elements and if they matches draw the horizontal line Using the following code :

canvas.drawLine(10, 10, 90, 10, paint);
canvas.drawLine(10, 20, 90, 20, paint);

EDIT : Please refer How to draw a line in android

Community
  • 1
  • 1
Avadhani Y
  • 7,276
  • 18
  • 55
  • 90
1

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.

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);
}

}

Refer: Dynamically draw lines between multiple GeoPoints in Android MapView

Community
  • 1
  • 1
Ponmalar
  • 6,656
  • 10
  • 46
  • 76
1

Place a custom view between your two columns and ready your canvas to draw anything. When you have made a successful selection . Get the bounds of those two selected views and use canvas to draw line from right and bottom end of start view to top and left of second view.

Shachillies
  • 1,596
  • 13
  • 12