The trick is all in the timing. It's a lot harder to time your way through two sets of hammers (ala in the above case), but once you're underneath the bros, taking them out becomes trivial - as you can just hit the block they're standing on.
The ones on the ground are still a matter of timing. Wait for the long pause between throws (happens once every 4 or 5 hammers) and run through the hammer arc. Stay between the hammer bro and his arc until the next pause (this may require moving a little with the hammer bro), and just when the next pause appears, take your chance and jump on his head. If timed correctly, he'll miss you with his last hammer, but not even get a chance to throw his next one.
As with all things, practice makes perfect. The more you tango with these creatures, the better you get at timing their throws and consistently avoiding those deadly hammers.