I've an android-app (Android SDK 10) with a WebView. On that WebView I have to use elements with a fixed position. Now I know, that there are Problems with fixed Elements, but with this Code in the HTML:
<meta name="viewport"
content="width=100%;
initial-scale=1;
maximum-scale=1;
minimum-scale=1;
user-scalable=no;">
And this for the Webview:
WebView mWebView = (WebView) findViewById(R.id.webView1);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.setVerticalScrollBarEnabled(true);
mWebView.loadUrl("path/to.html");
I am able to zoom when using the zoomcontrolls. Multitouch- and pinchzoom distorts the page however.
Is there a possibility to disable pich- and multitouchzoom but keep the zoom-controlls working?
With the suggestions of Vikalp Patel I've come to this solution:
CustomWebView mWebView = (CustomWebView) findViewById(R.id.webView1);
mWebView.loadUrl("path/to.html");
CustomWebView.java
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;
public class CustomWebView extends WebView {
/**
* Constructor
*/
public CustomWebView(Context context) {
super(context);
}
/**
* Constructor
*/
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/*
* (non-Javadoc)
*
* @see android.webkit.WebView#onTouchEvent(android.view.MotionEvent)
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1) {
this.getSettings().setSupportZoom(false);
this.getSettings().setBuiltInZoomControls(false);
} else {
this.getSettings().setSupportZoom(true);
this.getSettings().setBuiltInZoomControls(true);
}
return super.onTouchEvent(event);
}
}
Implementation in layout.xml
<package.path.CustomWebView
...
/>
Hope, that helps somebody.