【发布时间】: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