简体   繁体   English

未看到 SVG 标签图像 Android webview

[英]SVG tag image not seen Android webview

i'am using android WebView to show xhtml files in my app for display images i am using shouldInterceptRequest function but when i try to use code below我正在使用 android WebView在我的应用程序中显示 xhtml 文件以显示图像我正在使用shouldInterceptRequest函数但是当我尝试使用下面的代码时

<svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 1478 2544" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
  <image width="1478" height="2544" xlink:href="../Images/Antropoloji_Kapak_on_renk.jpg"></image>
</svg>

shouldInterceptRequest method not called and image could not shown未调用shouldInterceptRequest方法且无法显示图像

iam supporting all versions of android 4+ iam 支持所有版本的 android 4+

i can't change the content.我无法更改内容。 I should display exactly what i have given我应该准确地展示我所给予的

-edit- -编辑-

it turns out when i gave size of image smaller than screen it shows it事实证明,当我给出的图像尺寸小于屏幕时,它会显示它

but still i want to show it even if it is bigger than screen size但即使它大于屏幕尺寸,我仍然想显示它

I use following html page to display your svg:我使用以下 html 页面来显示您的 svg:

<html>
<head>
<title>SVG Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">

</head>
<body>
    <svg xmlns="http://www.w3.org/2000/svg" height="100%"
        preserveAspectRatio="xMidYMid meet" version="1.1"
        viewBox="0 0 3288 2188" width="100%"
        xmlns:xlink="http://www.w3.org/1999/xlink">
        <image width="3288" height="2188"
            xlink:href="file:///android_asset/image.jpg"></image>
    </svg>
</body>
</html>

To display embedded image into svg you should use path with file:///android_asset/ prefix.要将嵌入的图像显示到 svg 中,您应该使用带有file:///android_asset/前缀的路径。 If you want to embed image from another location then assets folder, you also should use file:/// prefix.如果您想从其他位置嵌入图像,然后是资产文件夹,您还应该使用file:///前缀。

Do you mean you can't change response from server?你的意思是你不能改变服务器的响应?

This case you can wrap <svg> tag with necessary <html> and <body>在这种情况下,您可以使用必要的<html><body>包裹<svg>标签

Try this:尝试这个:

String svgContent = ... // Your code of svg here
String pageContent = "<html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width'></head><body>" + svgContent + "</body></html>";
webview.loadData(pageContent, "text/html", "utf-8");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM