Grating-based X-ray phase-contrast and in particular dark-field radiography are promising new imaging modalities for medical applications. Currently, the potential advantage of dark-field imaging in early-stage diagnosis of pulmonary diseases in humans is being investigated. These studies make use of a comparatively large scanning interferometer at short acquisition times, which comes at the expense of a significantly reduced mechanical stability as compared to tabletop laboratory setups. Vibrations create random fluctuations of the grating alignment, causing artifacts in the resulting images. Here, we describe a novel maximum likelihood method for estimating this motion, thereby preventing these artifacts. It is tailored to scanning setups and does not require any sample-free areas. Unlike any previously described method, it accounts for motion in between as well as during exposures.