2015-06-20 116 views
0

我想在Android中創建水族館應用動態壁紙,我在其中繪製多個位圖現在我想添加觸摸事件,當我觸摸魚應該反應如何我可以知道哪些particuler魚被觸動如何可以做的在Android動態壁紙觸摸事件

private void draw() { 
    final SurfaceHolder holder = getSurfaceHolder(); 
    Canvas C = null; 
    try { 
     C = holder.lockCanvas(); 
     c.drawColor(Color.BLACK); 
     if (c != null) { 
      if (playingcounter3 == 20) { 
       playingcounter3 = 0; 
      } 
      c.drawBitmap(fish_c[1][playingcounter3], x1, 200, null); 
      if (x > width) { 
       x = -f1_width - width/7; 

      } 
     } 
    } finally { 
     if (c != null) holder.unlockCanvasAndPost(c); 
    } 
    handler.removeCallbacks(drawRunner); 
    if (visible) { 
     handler.postDelayed(drawRunner, 10); 
    } 
} 

回答

0

你必須檢查一個觸摸事件的像素值。

@Override 
public void onTouchEvent(MotionEvent event) 
{ 
    if (event.getAction() == MotionEvent.ACTION_DOWN) 
    {       
     event.getX(); 
     event.getY(); 
    }   

    super.onTouchEvent(event); 
}