A new segregation criterion based on the inelastic Enskog kinetic equation is derived to show the transition between the Brazil-nut effect (BNE) and the reverse Brazil-nut effect (RBNE) by varying the different parameters of the system. In contrast to previous theoretical attempts the approach is not limited to the near-elastic case, takes into account the influence of both thermal gradients and gravity and applies for moderate densities. The form of the phase-diagrams for the BNE/RBNE transition depends sensitively on the value of gravity relative to the thermal gradient, so that it is possible to switch between both states for given values of the mass and size ratios, the coefficients of restitution and the solid volume fraction. In particular, the influence of collisional dissipation on segregation becomes more important when the thermal gradient dominates over gravity than in the opposite limit. The present analysis extends previous results derived in the dilute limit case and is consistent with the findings of some recent experimental results.