我正在寻找一种方法来检测的WebView是否完全缩小。我知道你可以从ZoomOut()一个布尔返回值,但将进行缩小。我只是想简单地知道它是否可以。
I'm looking for a way to detect whether or not a WebView is zoomed out fully. I know you can get a boolean return value from ZoomOut(), but that will perform the zoom out. I just want to simply know whether or not it can.
我用我的自定义的WebView
类。
获取的WebView
的看法高度和内部HTML网页的或contentHeight
。
Get WebView
's view height and inner html web page's contentHeight
.
计算 defaultScale = WebView.getHeight()/ WebView.getContentHeight();
和 currentScale = WebView.getScale()
。
如果 defaultScale
< currentScale
它放大。
If defaultScale
< currentScale
it's zoomed.
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;
}
}