/**
* 如果输入法显示将指定的布局向上调整100DP,如果输入法隐藏了将指定的布局向下调整100DP
*
* @param context
* @param root需要调整的布局,为布局文件最外的布局
* @param width需要调整的宽度
* @param height需要调整的高度
*/
public static final void ControlLayout(final Context context, final View root, int width, int height) {
final int heightOffset = height;
final int widthOffset = width;
root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
root.getWindowVisibleDisplayFrame(rect);
int heightDiff = root.getRootView().getHeight() - (rect.bottom - rect.top);
// 键盘显示
if (heightDiff > 100) {
root.scrollTo(PhoneEnvUtils.dpTopx(context, widthOffset), PhoneEnvUtils.dpTopx(context, heightOffset));
// 键盘隐藏
} else {
root.scrollTo(0, 0);
}
}
});
}android 解决输入法键盘遮挡布局内容方法
最新推荐文章于 2020-12-19 19:29:54 发布
本文介绍了一种方法,在输入法显示时调整布局位置以适应键盘,反之则恢复原位。通过监听全局布局事件并计算布局与屏幕可见区域的距离,实现依据键盘状态自动调整布局高度和宽度。
338

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



