Likely a combination of hunting/gathering, gardening, and Elf magic, as can be gleaned from Galadriel's words to Sam:
“For you little gardener and lover of trees,' she said to Sam, 'I have only a small gift….. In this box there is earth from my orchard, and such blessing as Galadriel has still to bestow is upon it. It will not keep you on your road, nor defend you against any peril; but if you keep it and see your home again at last, then perhaps it may reward you. Though you should find all barren and laid waste, there will be few gardens in Middle-earth that will bloom like your garden, if you sprinkle this earth there. Then you may remember Galadriel, and catch a glimpse far off of Lórien....'
While I agree that hunting / gatheringgathering could not support a large permanent settlement, my guess is that Elves are a special case. Galadriel's gift to Sam was basically some dirt - however, even that amount, when sprinkled on the ground, would be enough to beat most gardens in Middle Earth. Well, there is probably a lot more of that dirt where it came from, not to mention Galadriel's blessings. I would assume that the Elves get a lot more out of their local plants than most people could out of theirs. Whatever benefit that bit of dirt holds for the Shire, the Elves have it in spades.
This probably holds true for other Elf settlements as well, even if not to the same extent as Lothlórien.