窗口向上滚动
// 在Manifest的配置Activity设置android:windowSoftInputMode="stateVisible|adjustResize"
// 目前的我的View为整个窗口大小, 如果不是可能要调整// 希望对有些人有帮助或者提示左右,可能有更好的方法
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
if(measuredHeight < getHeight() && input != null) { // 软键盘显示
// @input 为我自定义组件, input.mRightBY 为该组件的下边界
int distance = mInput.mRightBY - measuredHeight; // 计算滚动距离
if(distance > 0) {
scrollBy(0, distance); // 滚动
}
} else if(measuredHeight > getHeight()) { // 软键盘隐藏
scrollTo(0, 0); // 恢复
}
setMeasuredDimension(measuredWidth, measuredHeight);
}