具体用法不懂的,百度一下KeyboardListenLinearLayout
public class KeyboardListenLinearLayout extends LinearLayout {public static final byte KEYBOARD_STATE_SHOW = -3;
public static final byte KEYBOARD_STATE_HIDE = -2;
public static final byte KEYBOARD_STATE_INIT = -1;
private static final String TAG = KeyboardListenLinearLayout.class.getSimpleName();
private boolean mHasInit = false;
private boolean mHasKeyboard = false;
private int mHeight;
private IOnKeyboardStateChangedListener onKeyboardStateChangedListener;
public KeyboardListenLinearLayout(Context context) {
super(context);
}
public KeyboardListenLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setOnKeyboardStateChangedListener(
IOnKeyboardStateChangedListener onKeyboardStateChangedListener) {
this.onKeyboardStateChangedListener = onKeyboardStateChangedListener;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
//Log.i(TAG, "b : " + b);
if (!mHasInit) {
mHasInit = true;
mHeight = b;
if (onKeyboardStateChangedListener != null) {
onKeyboardStateChangedListener
.onKeyboardStateChanged(KEYBOARD_STATE_INIT);
}
}
Log.i(TAG, "mHasKeyboard"+mHasKeyboard +",mHeight:"+mHeight+",b:"+b);
if (mHasInit && mHasKeyboard && mHeight < b) {
mHasKeyboard = false;
if (onKeyboardStateChangedListener != null) {
onKeyboardStateChangedListener
.onKeyboardStateChanged(KEYBOARD_STATE_HIDE);
}
mHeight = b;
}else if (mHasInit && mHeight > b) {
mHasKeyboard = true;
if (onKeyboardStateChangedListener != null) {
onKeyboardStateChangedListener
.onKeyboardStateChanged(KEYBOARD_STATE_SHOW);
}
mHeight = b;
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}
public interface IOnKeyboardStateChangedListener {
public void onKeyboardStateChanged(int state);
}
}