Making a canvas' drawline clickable

Based on this answer, I created a directF list array.

Technique for making canvas drawLine () clickable?

here is the logic of my code:

List<RectF> rectFs;

Point pt1;
Point pt2;

      

then

path.moveTo(pt1.x, pt1.y);
path.lineTo(pt2.x, pt2.y);

path.computeBounds(rectF, true);
rectFs.add(rectF);

      

and then, I have this method to test the click and list of rectF items.

void lineHighighted(Point pt) {
    int ct = 0;
    for(RectF rectF : rectFs) {
        if(rectF.contains(pt.x, pt.y)) {
            ct++;
            Log.d(tag, ct + "HERE");
        }
    }
}

      

My problem is that sometimes the entire array is selected or "called", even I haven't touched that "line".

Are there any errors in my code?

Thanks in advance.

ADDITIONALLY:

I found out that after adding this code to my canvas:

path.moveTo(coor1[0], coor1[1]);
path.lineTo(coor2[0], coor2[1]);
canvas.drawPath(path, paint2);
path.computeBounds(rectf, true);

      

my previous result: before adding the code

it looks like this: enter image description here

+3


source to share


1 answer


This might be the case because I don't see your canvas interaction code being unable to post code that works completely. The logic is that one line should not overlap another in the case of the correct function. Hope I can help you.

    // setting where I will draw the ImageView for taking pictures

    // rec is used for onInterceptTouchEvent. I pass this from the
    // highest to lowest layer so that when this area of the screen
    // is pressed, it ignores the TouchView events and passes it to
    // this activity so that the button can be pressed.
    rec.set((int)((double)mScreenWidth*.85),
            (int)((double)mScreenHeight*.10) ,
            (int)((double)mScreenWidth*.85)+mButtonDrawable.getMinimumWidth(), 
            (int)((double)mScreenHeight*.70)+mButtonDrawable.getMinimumHeight());
    mButtonDrawable = null;

      



By this logic you can use whatever you want in this logic so the click doesn't overlap

0


source







All Articles