Which trolley are you using? Postwar Lionel, contemporary Lionel, MTH, etc.? Some trolleys--especially contemporary issue ones made in recent years--are equipped with smooth and easy bumping mechanisms that do not exert a lot of pressure when activated.
In any case, if I was making such a setup, I would glue O gauge cork (or foam) roadbed to the foam base and would probably use SuperStreets, which I have found to be quite reliable and good looking (especially for trolley operation). Small screws or even nails with a bit of glue applied and inserted through the roadbed into the base foam should certainly keep things in place well enough.
I plan to have a somewhat similar trolley operation running along the living room mantle of my still-under-renovation new home this holiday season since the basement train room will still be a work in progress. Will be using the new battery-controlled Bachmann On30 Norman Rockwell Christmas Trolley. Just received a set and it's ideal for mantle-top use because no conventional electrical connection is required (meaning no dangling cords and such).