This paper introduced a method of on-line gait planning based on preview control of ZMP( Zero Moment Point). With reference to the ZMP expression of humanoid robot,the horizontal momentum was introduced into the table-cart model's expression. Based on the extended table-cart model and combined with preview control theory,the on-line gait planning of robot was completed. Furthermore,to improve the stability of robot,the optimization problem of hip trajectory was transformed into the adjustment problem of the centroid trajectory,and the centroid trajectory was compensated by preview control to achieve robot gait optimization. The simulation results show that this method is effective.