Xamarin.Forms WidthRequest价值意义 [英] Xamarin.Forms WidthRequest value meaning

查看:561
本文介绍了Xamarin.Forms WidthRequest价值意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin.Forms,以下属性得到一个双:WidthRequest,HeightRequest,填充,间距等
那是什么数字的含义是什么?它是像素还是其他什么东西?
是我把响应设备屏幕尺寸这些属性值?
我应该如何决定我应该用什么样的价值,考虑到许多可用的屏幕尺寸?

In Xamarin.Forms, the following properties get a double: WidthRequest, HeightRequest, Padding, Spacing, etc. What's the meaning of that number? Is it pixels, or something else? Is the value that I put in those properties responsive to the device screen size? How should I decide what value I should use, taking into consideration the many screen sizes available?

我也尝试打印一些元素的宽度,并得到了-1作​​为结果。为什么呢?

I also tried to print some elements' width, and got -1 as a result. Why?

谢谢你是进步,

Thanks is advance, Or

推荐答案

Xamarin.Forms具有使用多达
可能的基础平台的约定的理念。按照这个理念,Xamarin.Forms程序员可以与由每个特定平台定义
尺寸。程序员通过Xamarin.Forms API
遇到所有尺寸都在这些平台特定的设备无关的单位。(C)

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)

在Xamarin窗体这些数字有在特定平台上为英寸厘米的关系。见下图:

In Xamarin Forms those numbers have relationships to inches and centimeters on a specific platform. See below:

这些都是在英寸


    的关系
  • 的iOS:160单位寸

  • Android版本:160单位寸

  • Windows手机:240个单位,以吋

这些都是在厘米如果您喜欢公制

These are relations in centimeters if you prefer metric system


  • 的iOS:64单位厘米

  • 安卓:64个单位为厘米

  • 的Windows Phone:96单位该厘米

例如,如果你希望你的显示为1英寸和2英寸,你会做的高度宽度的图片:

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)
};



概念同样适用于间距和填充。这些参数也有缺省值。初始设置为-1模拟值。当布局系统位置和大小网页上的所有这些属性的值才会有效。

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.

希望这有助于!

您可以了解更多关于它的书叫与Xamarin表单创建移动应用

You can learn more about it from book called "Creating Mobile Apps with Xamarin Forms"

这篇关于Xamarin.Forms WidthRequest价值意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆