android 解决输入法遮挡布局内容方法

/**
 * 如果输入法显示将指定的布局向上调整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);
     }
    }
   });
}