键盘弹起解决方案

在实际开发中,当我们弹起键盘的时候,会将我们的内容遮 挡,现在常见的
如果我们在activity 中设置 adjustResize,就是键盘弹起来了,将是activity 调整主窗口重新调整大小,为输入法腾出空间,
这里写图片描述
所以我们要在代码中监控变化高度,来判断键盘是不是弹起来了,

   private View.OnLayoutChangeListener mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            int height = bottom - top;
            if (mLastContentHeight == 0) {
                mLastContentHeight = height;
            }
            int screenHeight = DeviceUtil.getWindowHeight();
            mIsNeedShowKeyBoard = !(screenHeight - height > 200);
            resetFocus();
            /**keyboard showed*/
           if (mLastContentHeight - height > 200) {
               if (mHasImageDataList.size() > 0  && mCacheBean.isHitCommentPefectB) {
                   mScrollView.scrollTo(0,DeviceUtil.getScreenHeight()/2 - 200);
               } else {
                   mScrollView.fullScroll(View.FOCUS_DOWN);

               }
                mScrollView.setFocusable(false);
                mImageListEditor.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            }
            mLastContentHeight = height;

        }
    };

所以 这里是判断

mLastContentHeight - height > 200

判断键盘是不是弹起,这个判断条件给我相应的业务处理

猜你喜欢

转载自blog.csdn.net/ahubenkui/article/details/74901835