The expansion of the universe refers to the phenomenon where the space between galaxies is stretching, causing them to move apart from each other on large scales. However, on smaller scales, such as within a local group of galaxies, gravitational forces dominate over the expansion.
In the case of the Andromeda Galaxy, it is part of the Local Group, which also includes our own Milky Way galaxy and several other smaller galaxies. The gravitational attraction between the galaxies in the Local Group is stronger than the expansion of the universe on that scale. As a result, the Andromeda Galaxy and the Milky Way are moving toward each other under the influence of gravity.
While the universe as a whole may be expanding, the gravitational interactions within local structures can overcome the expansion and lead to relative motion between neighboring galaxies. The gravitational forces between galaxies can cause them to move in a way that is counter to the overall expansion of the universe.