Android 错误的Xamarin表单图像维度

Android 错误的Xamarin表单图像维度,android,image,xamarin,xamarin.android,xamarin.forms,Android,Image,Xamarin,Xamarin.android,Xamarin.forms,我想在基于Xamarin表单的Android项目中使用Visual Studio 2013和最新Xamaring版本显示一个60*60像素的png图像 我遵循以下步骤: 在Resources\Drawable文件夹中找到png图像 将映像的“构建操作”设置为AndroidResource 创建了Xamarin.Forms.Image对象,如下所示: 在App.GetMainPage()中,我只需将主页的内容设置为创建的图像 图像出现在页面中间,高度增加一倍,宽度增加了一倍!我做了网页截图

我想在基于Xamarin表单的Android项目中使用Visual Studio 2013和最新Xamaring版本显示一个60*60像素的png图像

我遵循以下步骤:

  • 在Resources\Drawable文件夹中找到png图像
  • 将映像的“构建操作”设置为AndroidResource
  • 创建了Xamarin.Forms.Image对象,如下所示:
  • 在App.GetMainPage()中,我只需将主页的内容设置为创建的图像
图像出现在页面中间,高度增加一倍,宽度增加了一倍!我做了网页截图并测量了图像,它是120*120而不是60*60

我重用了上面许多Xamarin示例中的代码


为什么要放大图像?

Xamarin.Forms不使用像素来调整视图元素的大小

所以你没有指定某个东西是60px,但在Android的情况下是60dpi

    protected static Image CreateHeaderLeftImage()
    {
        Image image = new Image();

        image.Source = Device.OnPlatform(null, ImageSource.FromFile("image.png"), null);

        image.WidthRequest = 60;
        image.HeightRequest = 60;

        image.VerticalOptions = LayoutOptions.Center;
        image.HorizontalOptions = LayoutOptions.Center;

        return image;
    }
public static Page GetMainPage()
{
    ContentPage contentPage = new ContentPage();

    contentPage.Content = CreateHeaderLeftImage();

    return contentPage;
}