2010-09-20 138 views
19

我目前正在android中構建一個web應用程序。我的應用在webview中運行,並通過iframe加載第三方內容。 iframe的大小是固定的,並且不應該被加載的內容改變。Webview iframe溢出

在臺式機Chrome瀏覽器中,它可以正常工作,並且可以通過滾動條滾動加載內容的溢出部分。然而,在android webview中,iframe往往會根據加載的內容調整自身大小,這會導致頁面佈局混亂。

有沒有其他人遇到同樣的問題?

回答

0

我發現了一種方法來避免這個討厭的問題。我禁用了iframe的滾動條,而是在應用程序中使用iscroll。這個滾動條與原來的幾乎相同,但我的HTC Magic手機速度較慢。

0

Tony。在我看來,這個技巧的關鍵點是你必須修復iframe的高度。然後,您可以將iscroll應用於iframe中的任何div元素。這裏是一個小的代碼片段:

// disable default touchmove handler 
    document.addEventListener('touchmove', function(e){ 
     e.preventDefault(); 
    }); 
    // make the div 'list' scrollable 
    var myScroll = new iScroll('list'); // <div id='list'>Blah</div> 

我在代碼中使用jQuery並將其與iScroll效果很好。

0

我正試圖在我的應用程序WebView中顯示一個Iframe,我遇到了無法使用CSS'overflow:hidden;'截斷我的iframe底部30像素的問題。我解決這個問題的方式是製作我自己的index.html文件,並將其作爲資源保存在本地應用程序中。

如果您沒有在項目中的「資產」文件夾,則轉到步驟1

(這是不一樣的「水庫」文件夾)

[在Windows 7 ]

步驟1 - 盤活資產的文件夾:在你的Android Studio項目點擊:

文件 - >新建 - >文件夾 - > Assets文件夾

Image showing how to make assets folder in Windows

步驟2 - 製作,將一個<div> 內握住你的<iframes>您可以複製下面的代碼在您的index.html文件中的代碼示例使用index.html:

<!DOCTYPE html> 
    <html> 
    <head> 
     <title></title> 
     <meta charset="utf-8" /> 
    </head> 
    <body style="margin:0px;"> 
     <div style="width:605px;height:875px;overflow:hidden;"> 
      <iframe src="https://docs.google.com/presentation/d/1QyNNURCVBme50SAuIceq3sh7Ky74LuWNeEM8B910aC4/embed?start=true&loop=true&delayms=2000" scrolling="no" frameborder="0" width="605" height="905" allowfullscreen="false" mozallowfullscreen="false" webkitallowfullscreen="false"></iframe> 
     </div> 
    </body> 
</html> 

步驟3 - 呼叫index.html文件在你的WebView

注 - (同上這個例子的WebView的是「main_ad」,改變這個ID是什麼什麼都你命名你的網頁視圖ID)

WebView webView = (WebView) findViewById(R.id.main_ad); 
webView.setWebViewClient(new WebViewClient()); 
webView.loadUrl("file:///android_asset/index.html"); //this is why you needed the assets folder 
webView.getSettings().setJavaScriptEnabled(true); 

希望這有助於即使1人與網頁視圖和iframe中

工作