获取软键盘的尺寸 [英] Getting the dimensions of the soft keyboard

查看:117
本文介绍了获取软键盘的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于获取软键盘的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆