带有ImageView和PDFRenderer的Android onTouchListener

时间:2014-12-17 11:32:37

标签: android listener pdfrenderer

有些人可以帮助我理解onTouchListners吗? 我是android的新手......并且做了一些更复杂的事情,我想......

1。我有一个主要的Activity类,它提供了7个pdf文件列表

2。存在一个PDF类,它将所选项目呈现为新的pdf文件(使用pdf渲染器完成)

第3。有一个翻转类来处理触摸翻页

我很困惑,在哪里放置以下方法,因为如果正确放置它永远不会被调用,它会帮助我提供下一个或上一个pdf页面..

public boolean onTouch(View v, MotionEvent event) {
         return gDetector.onTouchEvent(event);
   }

谢谢你..

1 个答案:

答案 0 :(得分:0)

以下是OnTouch工作原理的简单说明......

public boolean onTouch(View v, MotionEvent event) {

    int action = MotionEventCompat.getActionMasked(event);
    int pointerIndex = MotionEventCompat.getActionIndex(event);
    int x = (int)MotionEventCompat.getX(event,pointerIndex);
    int y = (int)MotionEventCompat.getY(event,pointerIndex);

    switch(action)
    {
    case MotionEvent.ACTION_DOWN:
        //
        // First finger was touched. Set "pointerIndex" to some value (lets say 0 or -1)
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        //
        // More finger touched when first finger is already touched.
        // Save "pointerIndex" corresponding to this touched object.
        //
        break;
    case MotionEvent.ACTION_MOVE:
        //
        // Finger with "pointerIndex" was moved.
        //
        break;
    case MotionEvent.ACTION_UP:
        //
        // The first touched finger went off.
        //
        break;
    case MotionEvent.ACTION_POINTER_UP:
        //
        // Finger with "pointerIndex" went off (other than first finger)
        //
        break;
    }
    return true;
}

我希望这会有所帮助。

祝你好运。 :)