【问题标题】:Android. Fit webview size to youtube video size安卓。使 webview 大小适合 youtube 视频大小
【发布时间】:2016-04-25 06:37:56
【问题描述】:

我想使用 android webview 播放 youtube 视频。 但我想让我的 webview 适合 youtube 视频大小。到目前为止,我的实现如下所示。

        String vid = TextUtils.extractYoutubeVId(body);
        if (StringUtils.isBlank(vid)) {
            return null;
        }

        String html = "<html > <head></head> <body style=\"margin:0 0 0 0; padding:0 0 0 0;\"> <iframe width=\"100%\" height=\"100%\" src=\"http://www.youtube.com/embed/___\" frameborder=\"0\"></iframe> </body> </html> ";
        html = html.replace("___", vid);

        mImportedVideoWebview.setWebChromeClient(new WebChromeClient());
        WebSettings webSettings = mImportedVideoWebview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mImportedVideoWebview.loadData(html, "text/html", "utf-8");

mImportedVideoWebview 只是一个 WebView,它的宽度是 MATCH_PARENT,高度是 350dp。

通过使用上面的代码,我可以播放 youtube 视频。

但是,我想将我的 webview 宽度设置为屏幕宽度,并将我的 webview 高度与 youtube 视频高度成比例。请大家帮帮我!

谢谢!

【问题讨论】:

    标签: android webview youtube


    【解决方案1】:

    使用下面的代码狙击希望它会

    <html><body><iframe frameborder=0 allowfullscreen width=100% height=100% src=link  frameborder=0 allowfullscreen></iframe></body></html>
    

    【讨论】:

      【解决方案2】:

      你可以使用:

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

      【讨论】:

        猜你喜欢
        • 2015-02-19
        • 2011-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-06
        • 1970-01-01
        相关资源
        最近更新 更多