》获取虚拟键盘的高度
View mYourView;
int mVisibleHeight;
boolean mIsKeyboardShow;
protected void onCreate(Bundle savedInstanceState) {
...
mYourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getKeyboardHeight();
}
});
...
}
private void getKeyboardHeight() {
Rect r = new Rect();
mYourView.getWindowVisibleDisplayFrame(r);
int visibleHeight = r.height();
if (mVisibleHeight == 0) {
mVisibleHeight = visibleHeight;
return;
}
if (mVisibleHeight == visibleHeight) {
return;
}
mVisibleHeight = visibleHeight;
// Magic is here
if (/* compare the visiable height to others */) {
mIsKeyboardShow = true;
} else {
mIsKeyboardShow = false;
}
}
》有待验证,正在进行中。。。