Communication relay is necessary for a swarm of collaborative Unmanned Aerial Vehicles (UAVs) executing missions in a large area, such as cooperative exploration, mapping tasks and so on, which assists for the quality of transmission in the swarm network. However, it remains a challenge to plan the mission of Relay UAVs (RUs) to enhance communication of the swarm considering the kinematics of UAVs and task sequences of a swarm. This paper proposes a two-layer relay planning framework for a fixed-wing UAV swarm consisting of coarse planning at the Ground Control Station (GCS) as well as refined trajectory planning onboard. The GCS planning layer evaluates the relay requirements in the swarm network to generate the initial deployment of RUs, aiming to minimize their numbers while maximizing utility. The beta-weak connectivity model is adopted to evaluate the swarm network topology constructed from the Minimum Spanning Tree (MST). Meanwhile, a Mixed-Integer Nonlinear Programming Problem (MINLP) is employed to determine the initial deployment of RUs including the number and accessing locations. Moreover, the onboard planning layer predicts the states of the Mission UAVs (MUs) connected to the RU using the Kalman filter. Based on these predictions, the trajectories of each RU are autonomously planned online to continuously guarantee stable network connectivity, which is achieved through Distributed Model Predictive Control (DMPC). Finally, numerical simulations are conducted to show the effectiveness of the proposed method.