I am so sorry if this is duplicate question. However, I did google related question in Stack overflow but still not find the correct solution for me.
I am using WebView to display an html file (stored in assest folder). The content of html file as below.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=4.0, user-scalable=1">
<meta charset="UTF-8">
<script type="text/javascript" src="jquery.js"></script>
...
<script type="text/javascript" src="convertCoordinates.js"></script>
<script>
$("embed").ready(function() {
G.init();
G.loadMaps(0);
});
</script>
</head>
<body style="margin: 0; padding: 0">
<!-- Inside this div the map will be rendered -->
<div id="map_container"> </div>
</body>
</html>
In general, html file has own javascrip to embed external SVG image on the run time. WebView is added into Framement via Fragment FrameLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#79b220"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<FrameLayout
android:id="@+id/webview_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</FrameLayout>
</RelativeLayout>
Android code
public class RAPINaviMainFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
private static final String TAG = "RAPINaviMainFragment";
private FrameLayout mFrameLayout;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_rapinavi_main, container,
false);
mFrameLayout = (FrameLayout) rootView.findViewById(R.id.webview_container);
if (((RAPINaviMainApplication)getActivity().getApplication()).isWebViewInitialized == false) {
RAPINaviMainApplication application = (RAPINaviMainApplication)getActivity().getApplication();
if (!application.isWebViewInitialized) {
if (intializeWebView()) {
application.isWebViewInitialized = true;
} else {
String html_value = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>RAPINavi</title></head><body style=\"width:300px; color: #00000; \"><br><br><br><p>Error in loading.</p></body></html>";
application.mWebView.loadData(html_value, "text/html", "UTF-8");
application.isWebViewInitialized = false;
}
}
}
return rootView;
}
...
@Override
public void onResume() {
Log.i(TAG, getClass().getSimpleName() + ":entered onResume()");
super.onResume();
mFrameLayout.addView(((RAPINaviMainApplication)getActivity().getApplication()).mWebView);
ActionBar actionBar = getActivity().getActionBar();
actionBar.setTitle(getString(R.string.app_name));
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
}
@Override
public void onPause() {
Log.i(TAG, getClass().getSimpleName() + ":entered onPause()");
super.onPause();
mFrameLayout.removeView(((RAPINaviMainApplication)getActivity().getApplication()).mWebView);
}
@SuppressLint("SetJavaScriptEnabled")
public boolean intializeWebView() {
RAPINaviMainApplication application = (RAPINaviMainApplication)getActivity().getApplication();
application.mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// Log.v("here","here");
// view.scrollBy(0, view.getContentHeight());
}
});
application.mWebView.getSettings().setJavaScriptEnabled(true);
application.mWebView.loadUrl(RAPINaviMainApplication.APP_ANDROID_HTML_PATH);
//application.mWebView.loadUrl(RAPINaviMainApplication.APP_JAVA_SCRIPT_PATH + "map_2.html");
application.mWebView.getSettings().setDisplayZoomControls(false);
application.mWebView.getSettings().setBuiltInZoomControls(true);
application.mWebView.getSettings().setUseWideViewPort(true);
application.mWebView.getSettings().setSupportZoom(true);
//application.mWebView.setInitialScale(0);
application.mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
application.mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
} else {
String msg = "At least API 16 is required!";
Toast.makeText(getActivity().getApplicationContext(), msg, Toast.LENGTH_LONG).show();
Log.w(TAG, msg);
return false;
}
CustomJavaScriptHandler mCustomJavaScriptHandler = new CustomJavaScriptHandler(getActivity());
application.mWebView.addJavascriptInterface(mCustomJavaScriptHandler, "svgapp");
mCustomJavaScriptHandler.addInstructor(new CustomJavaScriptHandler.JSInstructor() {
@Override
public void jsinstruct(String s) {
String parts[] = s.split(":");
}
});
return true;
}
}
The thing is that at the first launch, SVG image is loaded as expected with no white space.
But after user zoom in/ zoom out, a useless extra white space appear at the bottom and can not be removed.
I tried some solution in stackoverflow Remove unwanted White Space in WebView Android Problem with extra space at the bottom of android Webview But no one works. Anyone who know about this problem could give me a solution? Thank you all.
0 comments:
Post a Comment