2015-06-28 70 views
0

我有一個網頁視圖,並在其中加載Html。問題是,當它加載時,它看起來很小,通常不適合屏幕。任何1可以建議我解決這個問題?Webview加載youtube難度

myClass.class

mWebViewLayout.setVisibility(View.VISIBLE); 
      mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); 
      mWebView.getSettings().setJavaScriptEnabled(true); 
      mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
      mWebView.setScrollbarFadingEnabled(false); 
      mWebView.setWebChromeClient(new WebChromeClient() { 
      }); 
      WebSettings webSettings = mWebView.getSettings(); 
      mWebView.getSettings().setAllowContentAccess(true); 
      webSettings.setPluginState(WebSettings.PluginState.ON); 
      mWebView.canGoBack(); 



      final String html = "\n" + 
        "<!DOCTYPE html>\n" + 
        "<html>\n" + 
        " <head>\n" + 
        " <meta name=\"viewport\" content=\"width=device-width,target-densitydpi=device-dpi, initial-scale=1.0, maximum-scale=1.0\">\n" + 
        "  <title>Interface\t</title>\n" + 
        " </head>\n" + 
        " <body>" + 
        myIframeRecieved 
        + " </body></html>"; 

      //  mWebView.loadDataWithBaseURL(null, Select.from(VideoResource.class).where(Condition.prop("article_identifier").eq(selectedArticle.getArticleIdentifier())).first().getHtml(), "text/html", "UTF-8", null); 
      mWebView.loadData(html, "text/html; charset=UTF-8", null); 
      mWebView.setWebViewClient(new WebViewClient() { 
       public boolean shouldOverrideUrlLoading(WebView view, String url) { 

        view.loadData(html, "text/html; charset=UTF-8", null); 
        return true; 


       } 

       public void onPageFinished(WebView view, String url) { 

       } 

       public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 

       } 
      }); 

myIframeRecieved樣子:

<iframe frameborder='0' allowfullscreen='' src='http://www.youtube.com/embed/AOr4zw59A34?rel=0'></iframe><div class='caption'></div><div class='copyright'></div><div class='clear'></div> 

myIframeRecieved我不能修改,因爲我是從服務器

現在接受它時,即時通訊做過的WebView加載它看起來像this link

回答

1

嘗試設置width='100%' height='100%'到標籤,並查看這是否會更改佈局。

另一種嘗試的方法是從字符串中對url進行子串處理並將其傳遞給WebView;

事情是這樣的:

String url = extractUrlFrom(myIframeRecieved); // you implement this 
mWebView.loadUrl(url);