Improved popup behavior to deal with screen rotation