如何在Mupdf中实现双击放大?

时间:2013-05-03 03:52:59

标签: android mupdf

我在Android上研究Mupdf库。 我编译并成功运行了Sample。 这真是一个很棒的图书馆。 但是现在我在触发“双击”事件时缩放页面时出现问题。

首先,我实现了我的观看'听'双击事件:

public class MuPDFReaderView extends ReaderView implements GestureDetector.OnDoubleTapListener

然后,我覆盖了onDoubleTap()方法:

@Override
public boolean onDoubleTap(MotionEvent e) {
    // TODO Auto-generated method stub
    MuPDFView pageView = (MuPDFView) getDisplayedView();
    pageView.setScale(1.5f);
    Log.e("double tap", "" + e.getDownTime());
    return false;
}

当双击页面时,我可以在Logcat中看到“双击”日志,但页面没有缩放。我错在哪里?

2 个答案:

答案 0 :(得分:1)

我不确定为什么你的尝试不起作用,但这是另一种方法:

而不是在您的视图上实施GestureDetector.OnDoubleTapListener,而是直接在您展开的ReaderView上实施

public class ReaderView extends AdapterView<Adapter> implements 
    GestureDetector.OnGestureListener,
    GestureDetector.OnDoubleTapListener,
    ScaleGestureDetector.OnScaleGestureListener,
    Runnable { ... }

然后覆盖{i}这样的<{1}}方法

OnDoubleTap

此外,您还必须覆盖其他两种方法

@Override
public boolean onDoubleTap(MotionEvent e) {

    float previousScale = mScale;
    mScale += (mScale == 1f) ? 2f : -2f;
    float factor = mScale/previousScale;

    View v = mChildViews.get(mCurrent);
    if (v != null) {
        // Work out the focus point relative to the view top left
        int viewFocusX = (int)e.getX() - (v.getLeft() + mXScroll);
        int viewFocusY = (int)e.getY() - (v.getTop() + mYScroll);
        // Scroll to maintain the focus point
        mXScroll += viewFocusX - viewFocusX * factor;
        mYScroll += viewFocusY - viewFocusY * factor;
        requestLayout();
    }

    return true;
}

从Librelio Android示例中获取此代码

https://github.com/libreliodev/android

答案 1 :(得分:0)

您需要通过ReaderView处理此问题。修改比例并启动请求布局。

相关问题