Yes, you can.
Go to the device Settings > tap on Weight Loss Walking > enable Motion & Fitness option. When you walk on a treadmill, open the app Home screen, tap Start and select 'Indoor' mode.
Important: the app tracks the stats only if you keep your iPhone in the pocket or on your arm. Otherwise you have to fill in the logs manually: Menu > Logs > choose your workout > Pencil icon > enter the parameters you see on a treadmill screen > tap the check mark icon to save the logs.
Have a great workout in the gym!