code: private static int resolveGravity(int gravity, int width, int height,
                                        int intrinsicWidth, int intrinsicHeight) {
          if (!Gravity.isHorizontal(gravity)) {
              if (width < 0) {
                  gravity |= Gravity.FILL_HORIZONTAL;
              } else {
                  gravity |= Gravity.START;
              }
          }
  
          if (!Gravity.isVertical(gravity)) {
              if (height < 0) {
                  gravity |= Gravity.FILL_VERTICAL;
              } else {
                  gravity |= Gravity.TOP;
              }
          }
  
          // If a dimension if not specified, either implicitly or explicitly,
          // force FILL for that dimension's gravity. This ensures that colors
          // are handled correctly and ensures backward compatibility.
          if (width < 0 && intrinsicWidth < 0) {
              gravity |= Gravity.FILL_HORIZONTAL;
          }
  
          if (height < 0 && intrinsicHeight < 0) {
              gravity |= Gravity.FILL_VERTICAL;
          }
  
          return gravity;
      }
docs: Resolves layer gravity given explicit gravity and dimensions.
  <p/>
  If the client hasn't specified a gravity but has specified an explicit dimension, defaults to
  START or TOP. Otherwise, defaults to FILL to preserve legacy behavior.
  
  @param gravity layer gravity
  @param width   width of the layer if set, -1 otherwise
  @param height  height of the layer if set, -1 otherwise
  @return the default gravity for the layer