2010-09-20 45 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中

工作