如何实现onTouch功能android?

sut*_*ter 4 android gesture

嗨,我想创建加载大图像的应用程序,我可以移动它的简单手势.我必须将图像打印出来,但我无法实现onTouch,因此它保持静止.任何帮助apreseated.谢谢

我绘制图片的代码:

@Override protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
                   Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);

            // make the entire canvas white
            paint.setColor(Color.WHITE);
            canvas.drawPaint(paint);
paint.setStrokeWidth(1);
            paint.setPathEffect(null);
            paint.setColor(Color.GRAY);
            paint.setAntiAlias(true);


            for (int i=1; i < 100; i++){
                canvas.drawLine(0, i*1 , 600, i*20, paint);
                canvas.drawLine(i*1 ,0, i*20, 600, paint);      
            }
}
Run Code Online (Sandbox Code Playgroud)

big*_*nes 6

由于您已经在编写自定义视图,而不是设置一个侦听器,您可能希望GestureDetector在视图中包含一个侦听器,最重要的是避免使用该switch(e.getAction())事物,因为OnGestureListener它位于更高级别并且将为您提供已检测为的事件一个手势(滚动,投掷,长按...).

在这里查看示例.