private int softBoardHeight;
private void getSoftBoardHeight() {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (topStart == 0) {
topStart = getPanelHeight();// 没取到一直取
}
int cur = getPanelHeight();
if (topStart > 0 && softBoardHeight < 100 && cur > 0) {
softBoardHeight = topStart - cur;
}
}
});
}private int getPanelHeight() {
int[] lo = new int[2];
et_input.getLocationInWindow(lo);
return lo[1];
}
本文介绍了一种通过监听全局布局变化来获取软键盘高度的方法。利用ViewTreeObserver的addOnGlobalLayoutListener监听器,当软键盘弹出导致输入框位置变化时,能够计算出软键盘的实际高度。
1237

被折叠的 条评论
为什么被折叠?



