2014-12-28 30 views
3

基于这个答案,我创建了一个rectF的arrayList。制作画布'drawline clickable

Technique to make a canvas drawLine() clickable?

这里是我的代码的逻辑:

List<RectF> rectFs; 

Point pt1; 
Point pt2; 

然后

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

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

,然后,我有这样的方法来检查被点击和rectF数组列表。

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

我的问题是,有时,整个数组列表中选择或者“被称为”连我自己都没有碰那个“线”。

在我的代码中有任何错误?

在此先感谢。

补充:

我发现,在我的画布添加此代码后:

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

我以前的结果: before adding the code

就变成这样: enter image description here

回答

0

这可能是!因为我没有看到你的代码与画布生病的交互发布完全正常工作的代码。逻辑是,一个行不能覆盖另一个以防万一适当的函数。我可以帮你。

// 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; 

通过任何你想在这个逻辑,让点击这个逻辑,你可以使用恰巧不被覆盖

+0

感谢您的回答,先生。对此,我真的非常感激。 如果你能在顶部检查我的附加问题,可以吗? 在此先感谢:) –

+0

对不起,我无法加载你的图像,你可以重新上传他们??请:) – BiggDawgg

+0

我发现了这个问题。 http://stackoverflow.com/questions/27697251/a-specific-variable-in-an-object-is-becoming-identical-in-a-list 它就像path.computebounds(rectf,true)是问题。你有没有遇到过这个? –