Measles is highly infectious and spread through the air when someone who is infected coughs or sneezes. You don't have to be in close contact with someone to contract the infection. You could spend just a few minutes in the same room as someone and get it, though, the closer the contact, the higher the risk.
This virus can survive in closed areas (e.g. a bathroom) for up to two hours after an infected person with measles was there. So people who are in the same air space during this two hour period can become infected. It can also be spread through sharing food, drinks or cigarettes or kissing a person with measles.
An infected person can spread measles before knowing they have been infected. People are infectious to others from four days before to four days after the onset of rash.