6

我想在 Android 浏览器的网页中禁用 div 的双标签缩放。我尝试阻止触摸启动和触摸移动的默认设置,取消气泡/传播。我什至尝试过 jQuery mobile doubletap 事件,但它在元素缩放后触发。

4

3 回答 3

8

添加以下元。这将在大多数移动浏览器中停止双击放大,但会在您的页面上的任何地方停止它 - 而不仅仅是在您的单个 div 中。要么全有,要么全无,我害怕。

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
于 2013-01-31T23:05:23.933 回答
3

扩展WebView并用于GegstureDetector检测双击。

public class DummyWebView
    extends WebView
{

    private boolean doubleTapped;

    private GestureDetector.OnGestureListener gestureListener;
    private GestureDetector.OnDoubleTapListener doubleTapListener;
    private GestureDetector gestureDetector;

    public DummyWebView(Context context,
            AttributeSet attrs,
            int defStyle)
    {
        super(context, attrs, defStyle);

        getSettings().setUseWideViewPort(true);
        getSettings().setBuiltInZoomControls(true);

        // Gesture Listener
        gestureListener = new GestureDetector.OnGestureListener()
        {

            @Override
            public boolean onSingleTapUp(MotionEvent e)
            {
                // Nothing to do
                return false;
            }

            @Override
            public void onShowPress(MotionEvent e)
            {
                // Nothing to do
            }

            @Override
            public boolean onScroll(
                    MotionEvent e1,
                    MotionEvent e2,
                    float distanceX,
                    float distanceY)
            {
                // Nothing to do
                return false;
            }

            @Override
            public void onLongPress(MotionEvent e)
            {
                // Nothing to do
            }

            @Override
            public boolean onFling(
                    MotionEvent e1,
                    MotionEvent e2,
                    float velocityX,
                    float velocityY)
            {
                // Nothing to do
                return false;
            }

            @Override
            public boolean onDown(MotionEvent e)
            {
                // Nothing to do
                return false;
            }
        };

        // Double tap listener
        doubleTapListener = new GestureDetector.OnDoubleTapListener()
        {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e)
            {
                // Nothing to do
                return false;
            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent e)
            {
                // Double tap detected, we need to prevent 
                doubleTapped = true;
                return false;
            }

            @Override
            public boolean onDoubleTap(MotionEvent e)
            {


                return false;
            }
        };

        // Gesture detection on itself
        gestureDetector = new GestureDetector(getContext(), gestureListener_);
        gestureDetector.setOnDoubleTapListener(doubleTapListener);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {   
        if(gestureDetector.onTouchEvent(event)) return true;

        // Double tapping might perform zooming in/out
        // We need to prevent it
        if(doubleTapped)
        {
            doubleTapped = false;
            return doubleTapped;
        }
        return super.onTouchEvent(event);
    }


}
于 2013-01-29T07:49:13.160 回答
0
<meta name="viewport" user-scalable=no" />

如果您不想针对移动设备进行优化,将节省您的时间。

于 2016-10-24T12:21:00.577 回答