gpt4 book ai didi

android - 如何在 webview android 中调整 youtube 视频的大小?

转载 作者:太空宇宙 更新时间:2023-11-03 12:49:45 25 4
gpt4 key购买 nike

我正在我的应用程序中阅读提要。我可以阅读所有的图片、文字……我也可以阅读 youtube 视频。我的问题是我可以看到 youtube 视频的框架尺寸更大,我希望这个框架可以调整到 webview

看起来是这样的....

enter image description here

有人知道如何调整 youtube 视频的框架大小以适应 webview 吗?

提前致谢

这是我原始文件夹中的 html:

<html>
<head>
<title>News</title>
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
body {
max-width: 100%;
margin: 0px 0px; padding:0px;
text-align: left;
margin-bottom: 10px;
}

#base {
overflow: hidden;
width: 87.5%;
margin:0px auto;
}

#header {
border-bottom: 2px solid #f29a2e;
line-height: 1;
}

#writter {
border-bottom: 2px solid #f29a2e;
line-height: 1;
}

.title {

color: #333;
font-size: 25px;
}

.pubDate {
color: #A1A1A1;
text-align: left;
font-size: 14px;
}

.redac {
color: #A1A1A1;
text-align: left;
font-size: 14px;
}

.image {
max-width: 87.5%;
margin-top:10px;
margin-bottom:10px;
}

img, ul, ol {
display: block;
max-width:100%;
margin-top:10px;
margin-bottom:10px;
}

.content {
text-align:left;
<!--word-wrap:break-word;-->
font-size:16px;
color: #333
}

a {
color: #468CFF;
text-decoration: none;
}

</style>
</head>
<body>
<div id="base">
<div id="header">
<div class="title">
<p>_TITLE_</p>
</div>
<table>
<td>
<div class="pubDate">
<p>_PUBDATE_</p>
</div>
</td>
</table>
</div>
<div id="writter">
<div class="redact">
<p>_REDACTOR_</p>
</div>
</div>
<div class="content">
<p>_CONTENT_</p>
</div>
</div>
</body>
</html>

调用webview的Java类

 private void populateWebView() {
WebView webview = (WebView) findViewById(R.id.articulo_Webview);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setLoadWithOverviewMode(false);
webview.getSettings().setUseWideViewPort(true);
webview.loadDataWithBaseURL(null, "<!DOCTYPE HTML>"
+ populateHTML(R.raw.htmlnoticia), "text/html", "UTF-8", null);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
}

private String populateHTML(int resourceID) {
String html;
html = readTextFromResource(resourceID);
html = html.replace("_TITLE_", articulo.getTitulo());
html = html.replace("_PUBDATE_", "" + articulo.getFecha());
html = html.replace("_CONTENT_", articulo.getContenido());
html = html.replace("_REDACTOR_", articulo.getRedactor());
return html;
}

private String readTextFromResource(int resourceID) {
InputStream raw = getResources().openRawResource(resourceID);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int i;
try {
i = raw.read();
while (i != -1) {
stream.write(i);
i = raw.read();
}
raw.close();
} catch (IOException e) {
e.printStackTrace();
}
return stream.toString();
}

布局xml到webView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/articulo_Webview">
</WebView>
</LinearLayout>

最佳答案

我找到了解决方案。在 .html 中添加这个

iframe {
display: block;
max-width:100%;
margin-top:10px;
margin-bottom:10px;
}

关于android - 如何在 webview android 中调整 youtube 视频的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34121501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com