当前位置:网站首页>Click the input box to pop up the keyboard layout and move up

Click the input box to pop up the keyboard layout and move up

2022-04-23 18:42:00 Xiao Xiaofeng

  • Keyboard pop-up monitoring ,
 lineTaskbottom = (AutoLinearLayout)   findViewById(R.id.line_taskbottom);
 lineparams = new LinearLayout.LayoutParams(AutoLinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
editAdded.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            // When the keyboard pops up and hides, it will   Call this method .
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                // Get the visual part of the current interface 
                this.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
                // Get the height of the screen 
                int screenHeight = this.getWindow().getDecorView().getRootView().getHeight();
                // Here is used to get the height of the keyboard ,  When the keyboard doesn't pop up   This height is 0  When the keyboard pops up, it is a positive number 
                int heightDifference = screenHeight - r.bottom;
                Log.d("Keyboard Size", "Size: " + heightDifference);
                if (heightDifference > 0) {
                    lineparams.setMargins(0, heightDifference-120, 0, 0);
                    lineTaskbottom.setLayoutParams(lineparams);
                } else {
                    lineparams.setMargins(0, 10, 0, 0);
                    lineTaskbottom.setLayoutParams(lineparams);
                }
            }

        });

版权声明
本文为[Xiao Xiaofeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210604091467.html