您好我有一個網頁視圖,我希望它適合屏幕,使得用戶不必之前滾動水平或垂直的Android的WebView適合所有的內容篩選
我已搜查,許多建議以下,但它只限制了寬度,用戶仍然有垂直滾動:
engine = (WebView) (findViewById(R.id.webView1));
engine.loadUrl(www.example.com);
engine.getSettings().setLoadWithOverviewMode(true);
engine.getSettings().setUseWideViewPort(true);
我嘗試另一種方法,使用縮放方法,但它不會工作.....我得到的窗口寬度(1024個像素)而網頁內容的寬度也是1024像素!所以縮放不起作用....是否有任何方法來獲得正確的比例?
或....還有其他方法嗎?......謝謝!
// get the window width and height
Point outSize = new Point();
getWindowManager().getDefaultDisplay().getSize(outSize);
width = outSize.x;
height = outSize.y;
Log.i("Menuboard", "width: " + Integer.toString(width) + ", height: "
+ Integer.toString(height));
WebViewClient client = new WebViewClient() {
public void onPageFinished(WebView view, String url) {
int x = engine.getWidth();
int y = engine.getHeight();
Log.i("Menuboard", "web width: " + Integer.toString(x)
+ ", height: " + Integer.toString(y));
int scale1 = width * 100/x;
int scale2 = height * 100/y;
Log.i("Menuboard", "Scale1: " + Integer.toString(scale1)
+ ", Scale2: " + Integer.toString(scale2));
if (scale1 < scale2) {
engine.setInitialScale(scale1);
Log.i("Menuboard", "scale1");
} else if (scale1 > scale2) {
engine.setInitialScale(scale2);
Log.i("Menuboard", "scale2: " + Integer.toString(scale2));
}
}
};
engine = (WebView) (findViewById(R.id.webView1));
engine.loadUrl(string);
engine.getSettings().setBuiltInZoomControls(true);
engine.setPadding(0, 0, 0, 0);
engine.setWebViewClient(client);
只是一些注意事項:
要縮放網頁視圖:
engine = (WebView) (findViewById(R.id.webView1));
engine.loadUrl(www.example.com);
engine.getSettings().setBuiltInZoomControls(true);
engine.setPadding(0, 0, 0, 0);
engine.setInitialScale(50); // 0 - 100 where 100 is full scale
爲了得到窗口的寬度和高度:
Point outSize = new Point();
getWindowManager().getDefaultDisplay().getSize(outSize);
width = outSize.x;
height = outSize.y;
檢查此鏈接:http://stackoverflow.com/a/9756084/1168654和http://stackoverflow.com/questions/11922861/how-to-justify-text-on-a-textview- made-easy-android/11922862#11922862和http://stackoverflow.com/questions/15894644/how-we-get-the-text-of-a-texview-to-be-justified-dynamically/15894704#15894704 – 2013-04-09 10:33:35