How to draw a line dynamically in android [duplicate]

<strong>Possible Duplicate:</strong> 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.


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


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 <strong>How to draw a line in android</strong>


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.


  • How can I get the size of the Text Widget in flutter
  • How to draw a curved line between 2 points on canvas?
  • How to render HTML5 canvas within a loop
  • How to save draw paint with custom view android?
  • How to avoid changing background color of a chart with TeeChart Pro 2017 in Delphi10?
  • Android FingerPaint Example using Canvas, what is the offscreen Canvas?
  • JavaScript nested function prototype scope
  • Diamond Shaped Button with transparent borders
  • Canvas for drawing is a circle; random dots within canvas
  • how to make popup windows always on top?
  • How to show a badges count of ToolBarItem Icon in Xamarin Forms
  • Inserting a (g) node in the middle of a tree (SVG) using jQuery
  • write text on image and show it to a imageview
  • Application level floating views with navigation in Android
  • Android Studio Can't Find tools.jar
  • How to detect interior vertices in groups of 2d polygons? (E.g. ZIP Codes to determine a territory)
  • AndEngine Applying Transparancy to AndEngine View
  • Authentication in Play! and RestEasy
  • Using a canvas object in a thread to do simple animations - Java
  • jQuery ready not fired after rails link_to is clicked
  • Chart.js Multiple dataset
  • Bad request using file_get_contents for PUT request in PHP
  • Avoid links criss cross / overlap in d3.js using force layout
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How reduce the height of an mschart by breaking up the y-axis
  • script to move all files from one location to another location
  • ILMerge & Keep Assembly Name
  • Symfony2: How to get request parameter
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Traverse Array and Display in markup
  • Matrix multiplication with MKL
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • Busy indicator not showing up in wpf window [duplicate]
  • Android Heatmap on canvas or ImageView
  • Why do underscore prefixed variables exist?
  • java string with new operator and a literal