| | |
| | | |
| | | } |
| | | |
| | | private View mChildOfContent; |
| | | private final View mChildOfContent; |
| | | |
| | | private int usableHeightPrevious;//使用高度 |
| | | |
| | |
| | | int usableHeightNow = computeUsableHeight(); |
| | | |
| | | if (usableHeightNow != usableHeightPrevious) { |
| | | //可用高度无键盘 |
| | | //获取整个屏幕的高度 |
| | | int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); |
| | | |
| | | int heightDifference = usableHeightSansKeyboard - usableHeightNow; |
| | | |
| | | if (heightDifference > (usableHeightSansKeyboard / 4)) { |
| | | if (listener != null) { |
| | | listener.onKeyboardShow(); |
| | | listener.onKeyboardShow(heightDifference); |
| | | |
| | | } |
| | | |
| | | } else { |
| | | if (listener != null) { |
| | | listener.onKeyboardHide(); |
| | | listener.onKeyboardHide(heightDifference); |
| | | |
| | | } |
| | | |
| | |
| | | private int computeUsableHeight() { |
| | | Rect r = new Rect(); |
| | | |
| | | //获取可见窗口 |
| | | //获取可以显示的区域 |
| | | mChildOfContent.getWindowVisibleDisplayFrame(r); |
| | | |
| | | //Log.d(TAG,"rec bottom>" + r.bottom + " | rec top>" + r.top); |
| | | |
| | | return (r.bottom - r.top);// 全屏模式下: return r.bottom |
| | | |
| | | } |
| | | |
| | | public interface OnKeyboardVisibilityListener { |
| | | void onKeyboardShow(); |
| | | void onKeyboardShow(int h); |
| | | |
| | | void onKeyboardHide(); |
| | | void onKeyboardHide(int h); |
| | | |
| | | } |
| | | |