code: @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  
      int viewWidth = circleRadius + this.getPaddingLeft() + this.getPaddingRight();
      int viewHeight = circleRadius + this.getPaddingTop() + this.getPaddingBottom();
  
      int widthMode = MeasureSpec.getMode(widthMeasureSpec);
      int widthSize = MeasureSpec.getSize(widthMeasureSpec);
      int heightMode = MeasureSpec.getMode(heightMeasureSpec);
      int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  
      int width;
      int height;
  
      //Measure Width
      if (widthMode == MeasureSpec.EXACTLY) {
        //Must be this size
        width = widthSize;
      } else if (widthMode == MeasureSpec.AT_MOST) {
        //Can't be bigger than...
        width = Math.min(viewWidth, widthSize);
      } else {
        //Be whatever you want
        width = viewWidth;
      }
  
      //Measure Height
      if (heightMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.EXACTLY) {
        //Must be this size
        height = heightSize;
      } else if (heightMode == MeasureSpec.AT_MOST) {
        //Can't be bigger than...
        height = Math.min(viewHeight, heightSize);
      } else {
        //Be whatever you want
        height = viewHeight;
      }
  
      setMeasuredDimension(width, height);
    }
docs: ----------------------------------