如何绘制视图上的软键盘像WhatsApp的顶部?视图、键盘、WhatsApp

由网友(好听的名字带特殊符号)分享简介:我想知道它是如何可能增加查看键盘上像WhatsApp的和视频群聊的顶部。在聊天屏幕上,它们插入表情查看打开软键盘的顶部。I want to know how it's possible to add View on top of Keyboard like WhatsApp and Hangout. In chat...

我想知道它是如何可能增加查看键盘上像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

阅读全文

相关推荐

最新文章