code: private int measureWidth(int measureSpec) {
          float result;
          int specMode = MeasureSpec.getMode(measureSpec);
          int specSize = MeasureSpec.getSize(measureSpec);
  
          if ((specMode == MeasureSpec.EXACTLY) || (mRecyclerView == null)) {
              //We were told how big to be
              result = specSize;
          } else {
              //Calculate the width according the views count
              final int count = mRecyclerView.getAdapter().getItemCount();
              result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth);
              //Respect AT_MOST value if that was what is called for by measureSpec
              if (specMode == MeasureSpec.AT_MOST) {
                  result = Math.min(result, specSize);
              }
          }
          return (int)Math.ceil(result);
      }
docs: Determines the width of this view
  
  @param measureSpec
  A measureSpec packed into an int
  @return The width of the view, honoring constraints from measureSpec