【Android开发杂技】输入法高度获取(可监听变化)

来源:互联网 发布:西洋古玩软件 编辑:程序博客网 时间:2024/05/19 06:49
直接上代码:

RelativeLayout rootLayout; //根布局rootLayout = (RelativeLayout) this.findViewById(R.id.rootLayout);rootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {            @Override            public void onGlobalLayout() {                // TODO Auto-generated method stub                Rect r = new Rect();                rootLayout.getWindowVisibleDisplayFrame(r);                //r.top 是状态栏高度                int screenHeight = rootLayout.getRootView().getHeight();                int softHeight = screenHeight - (r.bottom - r.top);                Log.e("Keyboard Size", "Size: " + softHeight);                //boolean visible = heightDiff > screenHeight / 3;            }        });


0 0