有的时候,我们想实现这种效果。就是当EditText是处在焦点状态的时候,把上部分的布局给隐藏掉。
当其不处在焦点状态,又全部显示。为了实现这种效果,我们需要进行如下处理:
首先,自定义个ImageView
public class ImageViewCareIME extends ImageView{ ImeUiChangeListener mImeUiChangeListener; private int mPreBottom = 0; public ImageViewCareIME(Context context){ // TODO Auto-generated constructor stub super(context); } public static interface ImeUiChangeListener{ public void onImeUiChange(int bottom); } public void setOnImeUiChangeListener(ImeUiChangeListener imeUiChangeListener){ mImeUiChangeListener = imeUiChangeListener; } @Override protected void onDraw(Canvas canvas){ super.onDraw(canvas); Rect r = new Rect(); if(getGlobalVisibleRect(r)){ if(r.bottom != mPreBottom){ mPreBottom = r.bottom; System.out.println("Change: " + r.bottom); if(null != mImeUiChangeListener) mImeUiChangeListener.onImeUiChange(r.bottom); } } } }
在Activity界面
ImageViewCareIME imgTemp = new ImageViewCareIME(this); this.addContentView(imgTemp, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); this.screenHeight = dm.heightPixels; imgTemp.setOnImeUiChangeListener(new ImageViewCareIME.ImeUiChangeListener() { @Override public void onImeUiChange(int bottom) { if (AppraiseActivity.this.screenHeight == bottom) { editText.clearFocus(); layout.setVisibility(View.VISIBLE); } else { editText.requestFocus(); editText.setFocusable(true); layout.setVisibility(View.GONE); } } });
最后可能要在mainfest文件中把当前的Activity设置为
android:windowSoftInputMode="adjustResize|stateHidden"