Reputation: 7191
I have a problem with webView. As you can see on the picture there are white margins. I want to fill my screen that picture. How I can do that?
This is picture:
this is code:
WebView web = new WebView(getContext());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);
String imagePath = id;
String html = "<html><body><img src=\""+ imagePath + "\"></body></html>";
web.loadDataWithBaseURL("file:///mnt/sdcard/DinEgen/", html, "text/html","utf-8",null);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(1);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setScrollbarFadingEnabled(false);
XML file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<android.support.v4.view.ViewPager
android:id="@+id/presentation_viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="95"
/>
<LinearLayout
android:id="@+id/presentation_indicatorLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:gravity="center"
android:background="@drawable/choose_small_normal"
>
</LinearLayout>
</LinearLayout>
Upvotes: 3
Views: 10416
Reputation: 3297
I found this one works. This removes padding&margin and also make image sizes fit the screen width.
val warppedHtml = "<style>body { margin:0; padding:0;} img{display: inline;height: auto;max-width: 100%;}</style>${html}"
Upvotes: 0
Reputation: 844
Replace your tag with this one:
<body style='margin:0;padding:0;'>
Here's another tip for images in a webview: add a styling that fits images in the width of the screen. Works great on all screen sizes:
<style type='text/css'>
img {max-width: 100%;height:initial;} div,p,span,a {max-width: 100%;}
</style>
Upvotes: 15