android键盘监听

//contentlayout是最外层布局View mChildOfContent;int usableHeightPrevious;


mChildOfContent = contentlayout.getChildAt(0);mChildOfContent.getViewTreeObserver()               .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {                      public void onGlobalLayout() {   
                    Rect r = new Rect();                           mChildOfContent.getWindowVisibleDisplayFrame(r);    
                    int usableHeightNow = r.bottom - r.top;    
                    if (usableHeightNow != usableHeightPrevious) {        
                        int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();       
                        int heightDifference = usableHeightSansKeyboard - usableHeightNow;       
                        if (heightDifference > (usableHeightSansKeyboard / 4)) {           
                            // 键盘弹出        
                        } else {            
                            // 键盘收起         
                        }       
                    mChildOfContent.requestLayout();       
                    usableHeightPrevious = usableHeightNow;    
                }            }});
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010505059/article/details/80693081
个人分类: android
上一篇django-1-入门
下一篇Android报错:调用so库时“xxx.so has text relocations”
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭