解决方法1:在这里我们设置按百分比缩放级别这个意义上,当页面就绪的getScale将返回5.2f:

mView.setWebViewClient(new WebViewClient() {

@Override

public void onPageStarted(WebView view, String url, Bitmap favicon) {

view.setInitialScale(520);

super.onPageStarted(view, url, favicon);

}

解决方案2:这种方法是不是100%准确,因为它的舍入缩放为int值:

private WebView mView;

private Handler mZoomHandler = new Handler();

private Runnable mZoomRunnable = new Runnable() {

@Override

public void run() {

if ((int) mView.getScale() < WANTED_SCALE) {

mView.zoomIn();

mZoomHandler.postDelayed(this, 10);

} else if ((int) mView.getScale() > WANTED_SCALE) {

mView.zoomOut();

mZoomHandler.postDelayed(this, 10);

}

}

};

mView.getSettings().setSupportZoom(true);

mView.setWebViewClient(new WebViewClient() {

@Override

public void onPageFinished(WebView view, String url) {

super.onPageFinished(view, url);

mZoomRunnable.run();

}

});

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐