Is it possible to get the "real" width of a widget.newSwitch() object?

When positioning my newSwitches, I have been doing something similar to this:

mySwitch.x = display.contentWidth - (mySwitch.width \* 0.5) - 5

This should place its right hand edge 5 pixels in from the right edge of the screen.

When using the iOS 7 theme this seems to be fine, but on Android and on iOS6 there seems to be lots of empty space within the image, so the switch ends up being much further to the left.

Is there a reason for this, or will I have to guess the width of these objects, and hope that it doesn’t change in future?

Why not try the anchorX = 1 approach? This could work more consistently and you don’t have to care about the width of the widget. 

mySwitch.anchorX = 1 mySwitch.x = display.contentWidth - 5

It’s the same problem. If you imagine an image which is 100 pixels wide but only has content in the central 20 pixels, anchorX = 1 would still refer to a point which is actually an empty part of the image. 

When using the newswitch on android, it has this same empty space on either side. So anchorX = 1 actually refers to a point which is about 40 pixels to the right of where the switch visibly ends.

Ah I see what you mean. I don’t have an answer in this case but would love to find out if you do as I’m surely going to have the same problem sooner or later. How about finding the actual file and checking it for dimensions? Could that work?

Possibly but I’m not sure where I would find that file. For now I’ve just added 40 to the x position, and that seems to have fixed the problem in the short term.

Why not try the anchorX = 1 approach? This could work more consistently and you don’t have to care about the width of the widget. 

mySwitch.anchorX = 1 mySwitch.x = display.contentWidth - 5

It’s the same problem. If you imagine an image which is 100 pixels wide but only has content in the central 20 pixels, anchorX = 1 would still refer to a point which is actually an empty part of the image. 

When using the newswitch on android, it has this same empty space on either side. So anchorX = 1 actually refers to a point which is about 40 pixels to the right of where the switch visibly ends.

Ah I see what you mean. I don’t have an answer in this case but would love to find out if you do as I’m surely going to have the same problem sooner or later. How about finding the actual file and checking it for dimensions? Could that work?

Possibly but I’m not sure where I would find that file. For now I’ve just added 40 to the x position, and that seems to have fixed the problem in the short term.