0

我已经成功地使我的部分布局消失了

    activityRootView = findViewById(R.id.bottom_layout);    
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
           System.out.println("Height: "+heightDiff);

            if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...

            RelativeLayout bottom = (RelativeLayout)findViewById(R.id.bottom_layout);
            bottom.setVisibility(View.GONE);

            }else {

                RelativeLayout bottom = (RelativeLayout)findViewById(R.id.bottom_layout);
                bottom.setVisibility(View.VISIBLE);
            }
         }
    });
4

2 回答 2

2

试试这个

  @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
           button.setVisibility(View.VISIBLE);
          imageview.setVisibility(View.VISIBLE);
        InputMethodManager inputMethodManager = (InputMethodManager)  this.getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
    }
于 2013-06-14T09:28:39.863 回答
1

还有另一种更合适的方法来检测键盘何时出现和隐藏:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
    final int actualHeight = getHeight();

    if (actualHeight > proposedheight){
        // Keyboard is shown
    } else {
        // Keyboard is hidden
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

来源:键盘滑出时的任何android事件

于 2013-06-14T09:38:08.717 回答