如何绘制视图上的软键盘像WhatsApp的顶部? [英] How to draw view on top of soft keyboard like WhatsApp?

查看:130
本文介绍了如何绘制视图上的软键盘像WhatsApp的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道它是如何可能增加查看键盘上像WhatsApp的和视频群聊的顶部。在聊天屏幕上,它们插入表情查看打开软键盘的顶部。

I want to know how it's possible to add View on top of Keyboard like WhatsApp and Hangout. In chat screen, they insert emoticons view on top of the opened soft keyboard.

有谁知道如何实现这一行为呢?

Does anyone know how to achieve this behavior?

推荐答案

好了,我已经在这里聊天创建了一个示例键盘 ...

Well, I have created a sample keyboard for chatting here...

在这里,我使用弹出窗口显示弹出窗口和弹出的高度动态地通过键盘的高度来计算

Here, I use popup window for showing popup window and height of popup is calculated dynamically by height of keyboard

// Initially defining default height of keyboard which is equal to 230 dip
        final float popUpheight = getResources().getDimension(
                R.dimen.keyboard_height);
        changeKeyboardHeight((int) popUpheight);

// Creating a pop window for emoticons keyboard
    popupWindow = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT,
            (int) keyboardHeight, false);

和高度使用此功能来计算:

and height is calculated using this function :

/**
 * Checking keyboard height and keyboard visibility
 */
int previousHeightDiffrence = 0;
private void checkKeyboardHeight(final View parentLayout) {

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

                @Override
                public void onGlobalLayout() {

                    Rect r = new Rect();
                    parentLayout.getWindowVisibleDisplayFrame(r);

                    int screenHeight = parentLayout.getRootView()
                            .getHeight();
                    int heightDifference = screenHeight - (r.bottom);

                    if (previousHeightDiffrence - heightDifference > 50) {                          
                        popupWindow.dismiss();
                    }

                    previousHeightDiffrence = heightDifference;
                    if (heightDifference > 100) {

                        isKeyBoardVisible = true;
                        changeKeyboardHeight(heightDifference);

                    } else {

                        isKeyBoardVisible = false;

                    }

                }
            });

}

使用这些东西,我能够做一个完美的重叠键盘....

Using all these stuff i am able to make a perfect overlapping keyboard....

然后我吹弹出窗口viewpager和GridView的表情。

then i inflate popup window with viewpager and gridview for emoticons.

另外,我使用spannable字符串显示这些表情在列表视图和聊天窗口

Also, i use spannable string for showing these emoticons in listview and chat window

这篇关于如何绘制视图上的软键盘像WhatsApp的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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