1.用父View使用login.getViewTreeObserver().addOnGlobalLayoutListener()布局完成时回调里计算;
2.Rect rect = new Rect();
login.getWindowVisibleDisplayFrame(rect);用父View获取root在窗体的可视区域
3.int rootInvisibleHeight=
login.getRootView().getHeight()-rect.bottom;
用父View获取root在窗体的不可视区域高度(被其他View遮挡的区域高度);
4.if(rootInvisibleHeight>100){
int[] location = new int[2];
login_btn.getLocationInWindow(location);获取scrollToView在窗体的坐标
int srollHeight =(location[1]+login_btn.getHeight())+login.getScrollY()-rect.bottom;计算root滚动高度,使scrollToView在可见区域
if(srollHeight>50){
login.scrollTo(0,srollHeight);
}else{
login.scrollTo(0,0);
}
}else{
login.scrollTo(0,0);键盘隐藏
}