0

I have implemented custom webview and using swipe through gesture detector.swipe works perfectly... I have already set the buil in zoom control and set support zoom to true.

Still zoom control doent work.

below is the code in oncreate methid ..

wvBrowser = ( CustomWebView ) findViewById( R.id.wvBrowser );

    wvBrowser.getSettings( ).setLoadsImagesAutomatically( true );
    wvBrowser.getSettings( ).setJavaScriptEnabled( true );
    wvBrowser.getSettings( ).setBuiltInZoomControls( true );
    wvBrowser.getSettings( ).setSupportZoom( true );
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        wvBrowser.getSettings( ).setDisplayZoomControls(true);
    }

below is the custom gesture detector listener

private class CustomeGestureDetector extends SimpleOnGestureListener {      
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if(e1 == null || e2 == null) return false;
        if(e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false;
        else {
            try { // right to left swipe .. go to next page
                if(e1.getX() - e2.getX() > 100 && Math.abs(velocityX) > 800) {

                    moveDown();
                    return true;
                } //left to right swipe .. go to prev page
                else if (e2.getX() - e1.getX() > 100 && Math.abs(velocityX) > 800) {

                    moveUp();
                    return true;
                } 
            } catch (Exception e) { // nothing
            }
            return false;
        }
    }

}

Custom webview

public class CustomWebView extends WebView{
private GestureDetector gestureDetector;

public CustomWebView(Context context) {
    super(context);

}

public CustomWebView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

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

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return gestureDetector.onTouchEvent(ev) || super.onTouchEvent(ev);
}

public void setGestureDetector(GestureDetector gestureDetector) {
    this.gestureDetector = gestureDetector;
}



}

Please help me to set built in zoom control perfectly.

Anjali
  • 1,623
  • 5
  • 30
  • 50

0 Answers0