2016-03-08 73 views
0

重新布局我有这样网页视图缩放使内容在某些设备上

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_margin="@dimen/MarginDefault"> 

    <WebView 
     android:id="@+id/webView_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentTop="true"/> 

</RelativeLayout> 

,我想加载HTML字符串网页视图。我也希望内容可以缩放。

它在一些设备上运行良好,在其他设备上很奇怪。似乎有些设备在缩放后再次布置内容。这将导致在内容换行符(三星S4,华为登高伴侣7) enter image description here

变焦适用于Nexus 5X保护如预期的Nexus 7: enter image description here

当我放大的网站(在Chrome或其他浏览器),它可以以同样的方式在所有设备上工作(如在第二个屏幕截图中,没有换行符)。所以我一定在做错事。但是什么?

这里是我设置的内容:

webViewContent = (WebView) findViewById(R.id.webView_content); 
    webViewContent.getSettings().setBuiltInZoomControls(true); 
     webViewContent.getSettings().setDisplayZoomControls(false); 
     webViewContent.setInitialScale(100); 

     String content = "<!DOCTYPE html>\n" + 
       "<html>\n" + 
       "\t<head>\n" + 
       "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" + 
       "\t\t<title>Test</title>\n" + 
       "\t\t<style type=\"text/css\">\t\t* {font-family: \"helvetica\"; font-size: 16;}\t\ta:link {color: " + 
       "#004A94;} \t\ta:visited {color: #004A94;} \t\ta:hover {color: #004A94;} \t\ta:active {color: " + 
       "#004A94}</style>\n" + 
       "\t\t</head>\n" + 
       "\t<body>\t\n" + 
       "\t\t<div style=\"padding-bottom: 2em;\">\n" + 
       "\t\t\t<h2>Just another test string which is quite long</h2>\n" + 
       "\t\t</div>\n" + 
       "\t</body>\n" + 
       "</html>"; 


     webViewContent.loadDataWithBaseURL(ServerInformation.getBaseUrl(), 
       content 
       , "text/html", "UTF-8", ""); 

而且在一个更好的形状HTML字符串:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     <title>Test</title> 
     <style type="text/css">  * {font-family: "helvetica"; font-size: 16;}  a:link {color: #004A94;}  a:visited {color: #004A94;}   a:hover {color: #004A94;}  a:active {color: #004A94}</style> 
     </head> 
    <body> 
     <div style="padding-bottom: 2em;"> 
      <h2>Just another test string which is quite long</h2> 
     </div> 
    </body> 
</html> 

回答

1

我发现这个问题的原因。 将android:layout_height="wrap_content"更改为"match_parent"可解决此问题(如果事件不改变布局中的任何内容)。我仍然没有线索,为什么会发生这种情况,但至少现在起作用了。