我正在寻找一种方法来检测 WebView 是否完全缩小。我知道您可以从 ZoomOut() 获得 bool 返回值,但这将执行缩小。我只想简单地知道它是否可以。
最佳答案
我使用自定义 WebView
类。
获取WebView
的 View 高度和内部html网页的contentHeight
。
计算 defaultScale = WebView.getHeight()/WebView.getContentHeight();
和 currentScale = WebView.getScale()
。
如果 defaultScale
<currentScale
它被缩放。
public class NoZoomControllWebView extends WebView {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressWarnings("deprecation")
public boolean isZoomed () {
boolean result = false;
int contentHeight = getContentHeight();
int viewHeight = getHeight();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 ) {
float scale = getScale();
int temp = (int)(((float)viewHeight / (float)contentHeight) * 100);
if (temp < (int)(scale * 100)) {
result = true;
}
} else {
float scale = getScale();
int temp = (int)(((float)viewHeight / (float)contentHeight) * 100);
if (temp < (int)(scale * 100)) {
result = true;
}
}
return result;
}
}
关于android - 如何判断一个WebView是否一直缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4610715/