gpt4 book ai didi

安卓 WebView : zoom to a specific scale after content is loaded

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:32 25 4
gpt4 key购买 nike

WebView的内容加载后如何缩放到特定比例? (我不想重新加载内容。)

我正在使用 Android 2.3 及更高版本。

最佳答案

解决方案 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();
}
});

关于安卓 WebView : zoom to a specific scale after content is loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20674990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com