lineTaskbottom = (AutoLinearLayout) findViewById(R.id.line_taskbottom)
lineparams = new LinearLayout.LayoutParams(AutoLinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
editAdded.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//当键盘弹出隐藏的时候会 调用此方法。
@Override
public void onGlobalLayout() {
Rect r = new Rect()
//获取当前界面可视部分
this.getWindow().getDecorView().getWindowVisibleDisplayFrame(r)
//获取屏幕的高度
int screenHeight = this.getWindow().getDecorView().getRootView().getHeight()
//此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
int heightDifference = screenHeight - r.bottom
Log.d("Keyboard Size", "Size: " + heightDifference)
if (heightDifference > 0) {
lineparams.setMargins(0, heightDifference-120, 0, 0)
lineTaskbottom.setLayoutParams(lineparams)
} else {
lineparams.setMargins(0, 10, 0, 0)
lineTaskbottom.setLayoutParams(lineparams)
}
}
})