layout最外层的布局,如果不设置监听没效果
layout.addOnLayoutChangeListener(this);
findViewById(R.id.id_rl).addOnLayoutChangeListener(this); @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { Log.e("TAG", "onLayoutChange:"); if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > 0)) { //软键盘弹起 Log.e("TAG", "onLayoutChange: 软键盘弹起"); mButton.setVisibility(View.GONE); } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > 0)) { //当以前的现在的bottom-以前的bottom>0的时候也就是软件盘关闭 Log.e("TAG", "onLayoutChange: 软件盘关闭"); mButton.setVisibility(View.VISIBLE); } }