Xamarin.Forms has a philosophy of using the conventions of the underlying platforms as much as
possible. In accordance with this philosophy, the Xamarin.Forms programmer works with sizes defined
by each particular platform. All sizes that the programmer encounters through the Xamarin.Forms API
are in these platform-specific device-independent units.(c)
In Xamarin Forms those numbers have relationships to inches and centimeters on a specific platform. See below:
These are relations in inches
- iOS: 160 units to the inch
- Android: 160 units to the inch
- Windows Phone: 240 units to the inch
These are relations in centimeters if you prefer metric system
- iOS: 64 units to the centimeter
- Android: 64 units to the centimeters
- Windows Phone: 96 units to the centimeters
For Example if you want your to display an Image with width of 1 inch and height of 2 inches you would do:
var avatar = new Image{
WidthRequest = Device.OnPlatform(160, 160, 240),
HeightRequest = Device.OnPlatform(320, 320, 480)
};
Same concept applies to Spacing and Padding. These Parameters also have default values. The initial settings are “mock” values of –1. The values of these properties only become valid when the layout system has positioned and sized everything on the page.
Hope this helps!
You can learn more about it from book called "Creating Mobile Apps with Xamarin Forms"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…