在 WebViewClassic.java 中,如果实际比例小于默认比例,则displaySoftKeyboard会放大和平移。WebWiew.class mDefaultScale float 中有一个字段,源代码显示当您显示软键盘时,mActualScale 会发生变化。
因此,确保 mActualScale >= mDefaultScale 应该可以防止平移和重新缩放。(以下是来自 grepcode 站点的 WebView.java 的源代码——该站点不再运行。)
private void displaySoftKeyboard(boolean isTextView) {
InputMethodManager imm = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (isTextView) {
if (mWebTextView == null) return;
imm.showSoftInput(mWebTextView, 0);
if (mActualScale < mDefaultScale) {
// bring it back to the default scale so that user can enter
// text.
mInZoomOverview = false;
mZoomCenterX = mLastTouchX;
mZoomCenterY = mLastTouchY;
// do not change text wrap scale so that there is no reflow
setNewZoomScale(mDefaultScale, false, false);
adjustTextView(false);
}
}
else { // used by plugins
imm.showSoftInput(this, 0);
}
}
frameworks/base/core/java/android/webkit/WebViewClassic.java(对于 JellyBean api 17)中的 googleSource--WebViewClassic.java 的代码显示了类似的功能:
/**
* Called in response to a message from webkit telling us that the soft
* keyboard should be launched.
*/
private void displaySoftKeyboard(boolean isTextView) {
InputMethodManager imm = (InputMethodManager)
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
// bring it back to the default level scale so that user can enter text
boolean zoom = mZoomManager.getScale() < mZoomManager.getDefaultScale();
if (zoom) {
mZoomManager.setZoomCenter(mLastTouchX, mLastTouchY);
mZoomManager.setZoomScale(mZoomManager.getDefaultScale(), false);
}
// Used by plugins and contentEditable.
// Also used if the navigation cache is out of date, and
// does not recognize that a textfield is in focus. In that
// case, use WebView as the targeted view.
// see http://b/issue?id=2457459
imm.showSoftInput(mWebView, 0);
}