软键盘弹出后,Activity变形,popupWindow遮盖住。


转载请注明出处:http://blog.csdn.net/harryweasley/article/details/49124385


在看这个文章时候,你可能需要找这篇文章Android输入法弹出,布局上移,背景不会压缩

"adjustUnspecified" It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area.

This is the default setting for the behavior of the main window.

"adjustResize" The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan" The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

翻译成中文:

adjustUnspecified :


没有被指定是实现adjustResize这个模式还是实现adjustPan这个模式。系统会根据该Activity窗口是否有滚动控件,自动的挑选这两个模式的一种。如果该Activity有滚动控件,该窗口则使用adjustResize模式,重新调整大小,通过滚动可以使窗口的所有内容在一个更小的区域全部展示出来。如果该Activity没有滚动控件,则采用adjustPan模式。


如果不指定windowSoftInputMode,adjustUnspecified这个就是默认的的设置。


adjustResize:


Activity的主窗口总是调整大小,来为屏幕上的软键盘腾出空间。


adjustPan:


Activity的主窗口不会调整大小来为软键盘腾出空间。然而,窗口的内容自动的移动以便当前焦点永远不会被软键盘遮盖住,这样用户总是可以看到他们将要打字的内容。这通常看来是不令人满意的,因为用户可能需要关闭软键盘,才可以点击那些被软键盘遮住的控件。



注意:adjustResize模式,在Activity全屏的时候,不会响应。


由以上的解释,我们可以知道,如果想要背景图不被软键盘压缩变形,则必须要使用adjustPan方法,禁止Activity的窗口重新调整大小。




如果当前Activity弹出了popWindow,当软键盘弹出时,可以让popupWindow往上移动,以便露出所有的软键盘,需要这样设置。

mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

该方法必须要在mPopupWindow.showAtLocation()方法之前调用。



那么adjustResize方法在全屏的时候,不能使用,那应该怎么做呢。国外有个人做出来了,先实现以下的类。


public class AndroidBug5497Workaround {

    // For more information, see https://code.google.com/p/android/issues/detail?id=5497
    // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }

    private View mChildOfContent;
    private int usableHeightPrevious;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
            } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevious = usableHeightNow;
        }
    }

    private int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }

}


然后在setContentView方法后面,加入下面的代码就可以了:

AndroidBug5497Workaround.assistActivity(this);


参考文章:http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006


http://developer.android.com/guide/topics/manifest/activity-element.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值