Android中的动态壁纸触摸事件

时间:2015-06-20 10:55:17

标签: android live wallpaper

我想在Android中构建水族馆应用程序动态壁纸我在其中绘制多个Bitmap现在我想要添加触摸事件,当我触摸鱼时应该如何知道我怎么知道哪些特殊鱼被触摸我怎么能做到这一点

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);
    }
}

1 个答案:

答案 0 :(得分:0)

您必须检查触摸事件的像素值。

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

    super.onTouchEvent(event);
}