【问题标题】:Wrong Xamarin Forms Image Dimension错误的 Xamarin 表单图像尺寸
【发布时间】:2014-10-09 12:07:10
【问题描述】:

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

我按照以下步骤操作:

  • 在 Resources\Drawable 文件夹中找到 png 图像。
  • 将图像的“构建操作”设置为 AndroidResource
  • 按如下方式创建了 Xamarin.Forms.Image 对象:
    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;
    }
  • 在 App.GetMainPage() 中,我只是将主页的内容设置为创建的图像
public static Page GetMainPage()
{
    ContentPage contentPage = new ContentPage();

    contentPage.Content = CreateHeaderLeftImage();

    return contentPage;
}

图片出现在页面中间,高一倍,宽一倍!我做了我的页面截图并测量了图像,它是120 * 120而不是60 * 60!

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

为什么图片放大了?

【问题讨论】:

    标签: android image xamarin xamarin.android xamarin.forms


    【解决方案1】:

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

    http://forums.xamarin.com/discussion/18255/coordinate-units

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

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      相关资源
      最近更新 更多