gpt4 book ai didi

Android 在 iframe 中嵌入视频未根据 webview 高度变化调整大小

转载 作者:行者123 更新时间:2023-11-29 19:41:38 26 4
gpt4 key购买 nike

我正在尝试在 WebView 中播放嵌入的 youtube 视频。我的问题是当我旋转屏幕并调整 webview 高度时,iframe 没有改变它的高度。

String embedSrc = "https://www.youtube.com/embed/8SeRU_ZPDkE";
String iframe = "<html><body style=\"margin: 0; padding: 0; background: #000;\"><iframe width=\"100%\" height=\" 100% \" src=\"" + embedSrc + "frameborder=\"0\" allowfullscreen style=\"background: #000;\"></iframe></body></html>";

webView.loadData(iframe, "text/html", "utf-8");

WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(false);
settings.setDomStorageEnabled(true);

String userAgent = settings.getUserAgentString();
if (userAgent != null) {
userAgent = userAgent.replace("Android", "");
settings.setUserAgentString(userAgent);
}

//code to update webview height
webView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, newHeight));


//layout
<LinearLayout
android:id="@+id/root_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"
>

<WebView
android:id="@+id/webview"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:scrollbars="none"
/>

</LinearLayout>

我已经试过了

webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);

但是这段代码让 youtube Playback 控件变得非常小。

最佳答案

通过使用此 Responsive Iframe CSS tip 解决了 webview 中 iframe 的这个问题像这样:

<style>
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
}
.video-container iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div class="video-container">
<iframe src="http://www.youtube.com/embed/4aQwT3n2c1Q" allowfullscreen="" frameborder="0">
</iframe>
</div>

关于Android 在 iframe 中嵌入视频未根据 webview 高度变化调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38565768/

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