I use to have terrible anxiety. It's not completely better, but it's certainly improving thanks to medication. I assumed that the medication would magically make my fear of public spaces, especially the gym, completely go away and I could get on with my life. Medication, however, does not work that way, and I was stuck standing in the middle of the gym, having a mild panic attack because of all the people that were present and how I knewthey were looking at me and judging me.
It took me a while to learn that no, they were not looking at me. No one cares what you're doing at the gym. Your mind is going to be convinced that you are the center of attention at all times, especially in an environment like the gym where your body is practically put on display while you're working out. I learned in psychology that there is a term for this, where you think that you are the center of attention (especially during adolescence): imaginary audience. Although this is more prevalent when we're younger, it can still persist when we get to adulthood, and I think it comes out more when you have anxiety and are hyper aware of your surroundings.
How do you get over this anxiety in the gym? How do you convince yourself that no one is paying attention to you? Well, think about it: When you're in the gym, are you worried about what everyone else is doing? Personally, I'm not. I'm much too focused on what I'm doing and making sure that I'm not making a fool of myself than I am worried about what everyone else is doing. Once I realized this, things became so much easier for me.
Everyone in the gym is doing their own thing. They're working on their own routine, paying attention to their form, or listening to their music. They are not analyzing every detail, every squat you're taking. And trust me, if by some chance some weirdo IS focusing on what you're doing, they're the one with the problem, not you, and you should tell them they're making you uncomfortable. If the problem persists, maybe talk to your gyms management.
Also, remember: if you're self-conscious about your body, you have no reason to be. Whether you're big or little, strong or weak, you're all in the gym for pretty much the same reason: to be fit. I'm skinny, but not anywhere near fit, so I go to the gym, and I'm getting over my anxiety by realizing that I'm not under a spotlight when I approach the bench press.