code: private int setViewSize(int mode, int size, int drawableWidth) {
          int viewSize;
          switch (mode) {
              case MeasureSpec.EXACTLY:
                  viewSize = size;
                  break;
  
              case MeasureSpec.AT_MOST:
                  viewSize = Math.min(drawableWidth, size);
                  break;
  
              case MeasureSpec.UNSPECIFIED:
                  viewSize = drawableWidth;
                  break;
  
              default:
                  viewSize = size;
                  break;
          }
          return viewSize;
      }
docs: Set view dimensions based on layout params
  
  @param mode
  @param size
  @param drawableWidth
  @return