2014-12-28 27 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)是問題。你有沒有遇到過這個? –