The azimuthal anisotropy coefficient v_{2} of prompt D^{0}, D^{+}, D^{*+}, and D_{s}^{+} mesons was measured in midcentral (30%-50% centrality class) Pb-Pb collisions at a center-of-mass energy per nucleon pair sqrt[s_{NN}]=5.02 TeV, with the ALICE detector at the LHC. The D mesons were reconstructed via their hadronic decays at midrapidity, |y|<0.8, in the transverse momentum interval 1<p_{T}<24 GeV/c. The measured D-meson v_{2} has similar values as that of charged pions. The D_{s}^{+} v_{2}, measured for the first time, is found to be compatible with that of nonstrange D mesons. The measurements are compared with theoretical calculations of charm-quark transport in a hydrodynamically expanding medium and have the potential to constrain medium parameters.