There is a webview I disabled the scrolling. And it is equal to the width of the android phone screen size.
The problem is the content in the webview is not auto resize but display outside of the webview (as I disable the scrolling, but the webview size is not "exactly" the screen width) , you may have a look at screenshot
I already add
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'>
and
newsContent.getSettings().setUseWideViewPort(true);
newsContent.getSettings().setLoadWithOverviewMode(true);
but still not work. Thanks.
Webview XML:
<WebView
android:id="@+id/newsContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:background="#ffffff" />
Webview JAVA:
StringBuilder sb = new StringBuilder();
sb.append("<HTML><HEAD><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'><LINK href=\"news.css\" type=\"text/css\" rel=\"stylesheet\"/><script src=\"jquery-1.10.2.js\" type=\"text/javascript\"></script></HEAD><body>");
sb.append(newsItem.description.toString());
sb.append("<script>$('img').on('click', function() {app.zoom($(this).attr('src'));});</script></body></HTML>");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
newsContent.getSettings().setAllowUniversalAccessFromFileURLs(true);
newsContent.getSettings().setAllowFileAccessFromFileURLs(true);
}
newsContent.setWebChromeClient(new WebChromeClient());
newsContent.setWebViewClient(new WebViewClient());
newsContent.getSettings().setUseWideViewPort(true);
newsContent.getSettings().setLoadWithOverviewMode(true);
newsContent.getSettings().setJavaScriptEnabled(true);
newsContent.addJavascriptInterface(new WebViewJavaScriptInterface(), "app");
newsContent.loadDataWithBaseURL("file:///android_asset/", sb.toString(), "text/html", "utf-8", null);
newsContent.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
newsContent.setVerticalScrollBarEnabled(false);
newsContent.setHorizontalScrollBarEnabled(false);