Android Webview-使用一个loadUrl缩放图像以适合屏幕 [英] Android Webview - Scale image to fit screen properly with one loadUrl

查看:54
本文介绍了Android Webview-使用一个loadUrl缩放图像以适合屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序Webview中,第一次加载文本html时不会出现问题,但是当您尝试在开始活动后尝试将包含单个大图像的页面作为第一页时,就会出现问题.

In my app webview, there's no problem to fit text html to screen on first load but the problem occurs when you try to load a page that contains a single large image as the first page after you start an activity.

如果在活动开始后加载任何类型的页面后尝试加载单个大图像的页面,则单个大图像的页面将完全适合屏幕.但是,如果您尝试在活动开始后的第一页加载单个大图像的页面,它将显示一个带有小图像的页面,该页面周围有很多空白.

If you try to load a page with single large image after you load any type of page after the activity started, the page with single large image will fit to the screen with no problem. But, if you try to load the page with single large image as the first page after the activity started, it will display a page with small image with lots of white space around it.

是否可以通过一种WebView#loadUrl方法使页面具有单个大图像?

Is there any way to fit the page with single large image with one WebView#loadUrl method?

这是我的html页面,其中包含单个大图像源

This is my html page with single large image source

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Cover Title</title>
    </head>
    <body>
        <div id="cover">
            <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 1125 1600" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
                <image height="1600" width="1125" xlink:href="../images/v01-cover.jpg" />
            </svg>
        </div>
    </body>
</html>

我已经尝试设置 setLoadWithOverviewMode(true)和setUseWideViewPort(true),但对我来说不起作用.
在此链接中阅读超级注释 Android WebView,将图像缩放为适合屏幕

I already tried setting the setLoadWithOverviewMode(true) and setUseWideViewPort(true) but didn't work out for me.
Read supermus comment in this link Android WebView, Scaling Image to fit the screen

推荐答案

如果您使用的是WebView,则期望带有视口的meta标签(通过这种方式,即使在加载和加载期间,它也可以计算带有像素值的宽度之类的内容失败).在文档的< head> 上添加< meta name ="viewport" content ="width = device-width,initial-scale = 1"> .这应该可以解决一些问题.

If you are using a WebView, a meta tag with the viewport is expect (this way, it can calculate stuff like width with pixel values, even during load and failures). Add <meta name="viewport" content="width=device-width, initial-scale=1"> on the <head> of your document. This should fix some issues.

这篇关于Android Webview-使用一个loadUrl缩放图像以适合屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆