简体   繁体   English

带有ImageView和PDFRenderer的Android onTouchListener

[英]Android onTouchListener with ImageView and PDFRenderer

Can some body help me with some understanding about onTouchListners ?? 某些机构可以帮助我对onTouchListners有所了解onTouchListners I am new to android...and doing something more complex I guess.. 我是android的新手,而我做的事情更复杂。

1. I have a main Activity class which renders a list of 7 pdf files 1.我有一个主要的Activity类,可显示7个pdf文件的列表

2. there exists a PDF class which renders the selected item as a new pdf file(done using pdf renderer) 2.存在一个PDF类,该类将所选项目呈现为新的pdf文件(使用pdf呈现器完成)

3. there exists a flip class to take care of flipping pages on touch 3.存在一个翻转类,用于处理触摸时翻转的页面

I am confused about, where to place the following method as it is never getting called if placed correctly and it shud help me deliver the next or previous pdf page.. 我很困惑,在哪里放置以下方法,因为如果放置正确,它将永远不会被调用,它有助于我提供下一个或上一个pdf页面。

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

Thank u.. 感谢你..

Here is a simple explanation of how OnTouch works... 这是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;
}

I hope this helps. 我希望这有帮助。

Good Luck. 祝好运。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM