android - Technique to make a canvas drawLine() clickable? -


i'm working on app plots nodes on map, , each node has edges represented line between them. i've drawn edges using canvas , drawline(), useful if lines clickable. mean method of allowing user touch line or think they're touching line , event can trigger. (like display edge info, etc...)

i can't rightly attach touch event line i've drawn canvas, thinking of placing imageviews inbetween ends of each edge line that's drawn. imageview dot it's clear touch event triggers.

does have other suggestions? i'm looking ideas i've missed. maybe there's in android api can i'm unaware of.

thanks in advance tips!

use path draw line:

path linepath; paint p; rectf rectf; float point1x, point1y, point2x, point2y;  // initialize components  // draw line linepath.moveto(point1x, point1y);  linepath.lineto(point2x, point2y);  canvas.drawpath(linepath, p);  linepath.computebounds(rectf, true); 

override ontouchevent(motionevent):

@override public boolean ontouchevent(motionevent event) {      float touchx = event.getx();     float touchy = event.gety();      switch (event.getaction()) {     case motionevent.action_down:         if (rectf.contains(touchx, touchy)) {             // line has been clicked         }         break;     }     return true; } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -