private void updateParams(int x, int y, int gravity, ViewGroup.LayoutParams params) {
    int horizontalGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;

    switch (horizontalGravity) {
      case Gravity.LEFT:
        setLeftMargin(params, (int) (x - mBackground.getPaddingLeft()));
        break;
      case Gravity.CENTER_HORIZONTAL:
        setLeftMargin(params, (int) (x - mBackground.getCenterX()));
        break;
      case Gravity.RIGHT:
        setLeftMargin(
            params, (int) (x - mBackground.getPaddingLeft() - mBackground.getRadius() * 2));
        break;
      default:
        setLeftMargin(params, (int) (x - mBackground.getPaddingLeft()));
        break;
    }

    int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

    switch (verticalGravity) {
      case Gravity.TOP:
        setTopMargin(params, (int) (y - mBackground.getPaddingTop()));
        break;
      case Gravity.CENTER_VERTICAL:
        setTopMargin(params, (int) (y - mBackground.getCenterY()));
        break;
      case Gravity.BOTTOM:
        setTopMargin(params, (int) (y - mBackground.getPaddingTop() - mBackground.getRadius() * 2));
        break;
      default:
        setTopMargin(params, (int) (y - mBackground.getPaddingTop()));
        break;
    }

    setLayoutParams(params);
  }
 /** @return The radius of the button. */
 public int getRadius() {
   return mBackground.getRadius();
 }