public int viewVisiableHeight() {
//获取当前屏幕内容的高度
int screenHeight = getWindow().getDecorView().getHeight();
//获取View可见区域的bottom
Rect rect =new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
LogUtils.e("height...base..", rect.bottom +" - " + screenHeight +" = " + (screenHeight - rect.bottom));
return screenHeight - rect.bottom;
}
// private void setCommentMargin(boolean isVisiable) {
// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutComment.getLayoutParams();
//// LogUtils.e("height...", viewVisiableHeight() + "");
// if (isVisiable) {
// params.setMargins(0, 0, 0, viewVisiableHeight());
// } else {
// params.setMargins(0, 0, 0, 0);
// }
// layoutComment.setLayoutParams(params);
// }
根据上面的方法,在弹出软键盘的位置,加上,建议玩几秒钟获取软键盘高!然后让EditText布局marginBottom从上面获取的 高度就好了!
同理当软键盘消失的时候,设置marginBottom为0!
网友评论