在 web 视图中适合图像 [英] Fit image in webview
问题描述
我打算在 webview 中显示来自 SD 卡的图像,以利用他内置的 webview 缩放功能.但是,我在显示大于屏幕尺寸(例如 1800x1200)以适合屏幕的图像时遇到了问题,例如在 ImageView 中.我希望图像首先完整显示并为用户提供缩放控制.我曾尝试将 WRAP_CONTENT 用于 webview 的宽度和高度,但这不起作用.有任何想法吗?以下是我正在使用的代码片段:
I am planning to display images from SD card in a webview in order to take advantage of he built in zoom capabilities of webview. However, I am facing an issue with displaying images that are bigger than screen size (e.g. 1800x1200) to fit the screen initially, like in an ImageView. I want the image to be displayed in full at first and provide zoom control to the users. I have tried using WRAP_CONTENT for webview's width and height, but that does not work. Any ideas? Following is a code snippet I am using:
String path = getRealPathFromURI(mUriList.get(0)); // this gets the file path
webView = (WebView) findViewById(R.id.WebView01);
WebSettings settings= webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
webView.loadUrl("file://" + path);
推荐答案
private WebView mWebView2;
mWebView2 = (WebView)findViewById(R.id.webview);
mWebView2.getSettings().setJavaScriptEnabled(true);
mWebView2.getSettings().setLoadWithOverviewMode(true);
mWebView2.getSettings().setUseWideViewPort(true);
mWebView2.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView2.setScrollbarFadingEnabled(true);
mWebView2.loadDataWithBaseURL("file:///android_asset/", "<img src="banner5.png" height="98%" width="100%"/>", "text/html", "utf-8", null);
图片在assets文件夹中
Images are in the assets folder
这篇关于在 web 视图中适合图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!