Paul
these are not silly questions. There are 2 things going on here - the local and the global.
At a local level, M31 and the Milky Way are moving towards each other. This is simply a function of gravity although its not so easy to model as all of the other galaxies (and other matter) in the Local Group of galaxies also need to be taken into account. Similarly, the LMC and SMC are gravitationally bound and will make a close pass by the MW - as has possibly happened before.
On the large scale, the universe is expanding. Here's the interesting bit - it is not that everything is moving away from us, it is the space between everything is expanding. The classic explanation is to think of the universe as a balloon with all the galaxies represented by dots on the balloon's surface. As the ballon is inflated, all of the dots move away from each other.
So the space between us and M31 is expanding but the gravitational force between us is far greater than that of the "dark energy" that is driving us apart. Recognised that gravity is an inverse square law so if you double the distance between galaxies, the gravitational force between them drops by 1/4 not 1/2 if the scaling were linear. So objects that are close (relatively) like M31 and the MW have sufficient gravitational force to remain bound.
I hope that helps
Pete
|