android 网页 缩放比例,Android WebView:在加载内容后缩放到特定比例
解决方法1:在这里我们设置按百分比缩放级别这个意义上,当页面就绪的getScale将返回5.2f:mView.setWebViewClient(new WebViewClient() {@Overridepublic void onPageStarted(WebView view, String url, Bitmap favicon) {view.setInitialScale(520);sup
解决方法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();
}
});
更多推荐
所有评论(0)