获取软键盘的尺寸尺寸、键盘

由网友(ωǒ、尐流氓)分享简介:有没有办法知道键盘是显示在屏幕的大小呢?Is there a way to know the size of the keyboard that is shown in the screen?我使用Cocos2dx进行编程,但我想知道在Android中的部分或科科斯部分屏幕显示的键盘的高度,也没关系。I am u...

有没有办法知道键盘是显示在屏幕的大小呢?

Is there a way to know the size of the keyboard that is shown in the screen?

我使用Cocos2dx进行编程,但我想知道在Android中的部分或科科斯部分屏幕显示的键盘的高度,也没关系。

I am using Cocos2dx for programming, but I want to know the height of the keyboard shown in screen in the part of Android or the part of Cocos, it does not matter.

我知道,键盘具有的getHeight()方法,但我不希望创建新的键盘,我想使用默认的。

I know that Keyboard has a getHeight() method but I don't want to create new keyboards, i want to use the default one.

推荐答案

我们用这个做了

myLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    // TODO Auto-generated method stub
                    Rect r = new Rect();
                    parent.getWindowVisibleDisplayFrame(r);

                    int screenHeight = parent.getRootView().getHeight();
                    int heightDifference = screenHeight - (r.bottom - r.top);
                    Log.d("Keyboard Size", "Size: " + heightDifference);

                    //boolean visible = heightDiff > screenHeight / 3;
                }
            });

我们只调整与键盘的意见,所以我们可以利用这一点。

We only resize views with the keyboard, so we could use this.

阅读全文

相关推荐

最新文章