Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未看到SVG标记图像Android webview_Android_Svg_Webview_Xhtml - Fatal编程技术网

未看到SVG标记图像Android webview

未看到SVG标记图像Android webview,android,svg,webview,xhtml,Android,Svg,Webview,Xhtml,我正在使用安卓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

我正在使用安卓
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
方法未调用,图像无法显示

iam支持所有版本的android 4+

我不能改变内容。 我应该准确地展示我所付出的

-编辑-

结果是,当我给出的图像尺寸小于屏幕显示的尺寸时


但我仍然想显示它,即使它大于屏幕大小

我使用以下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>

SVG测试

要将嵌入的图像显示到svg中,应使用带有
file:///android_asset/
前缀。如果您想从其他位置嵌入图像,然后从资产文件夹嵌入图像,您还应该使用
文件://
前缀。

您的意思是不能更改服务器的响应吗

这种情况下,您可以使用必要的
包装
标签

试试这个:

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");
String svgContent=…//您的svg代码在这里
字符串pageContent=“”+svgContent+”;
加载数据(页面内容,“文本/html”,“utf-8”);

您在哪个版本的android平台上运行此功能?我在android 4.1SVG上进行了测试,它应该在4+中得到支持,尽管我不确定这样的子元素的加载是否通过shouldInterceptRequest发送(我原以为是这样)。你确定图像存在吗?你能试试其他一些更基本的SVG元素,看看它们是否被绘制出来吗?我确信图像存在,因为同一个文件在我的应用程序的iOS版本上工作,我也写到了这是通过file://URL本地加载的还是从远程服务器加载的?我无法更改内容。我应该准确地显示我在svg中给出的内容。您的svg中的一个错误是使用了相对文件路径,而不是绝对文件路径。只用file:///android_asset/image.jpg. 事实上,您需要在svg的href attr中使用uri。您真的认为它不在html页面中吗?