【发布时间】:2018-03-08 09:46:17
【问题描述】:
我是 Xamarin 的新开发人员。我正在尝试构建一个简单的按钮图像,问题是 图像,它没有出现在我的手机中。 我还使用 VS2017 和我的手机实时调试 xamarin。 当我实时构建和运行时,没有任何警告或错误。所以很难看出哪里出了问题。
到目前为止我做了什么:
我检查了 Android 文件夹资源中的图像,并检查了图标的尺寸是否正确。
我执行以下步骤:清理解决方案,重建解决方案,构建解决方案并重新启动 VS2017
App.xaml.cs:
public App ()
{
InitializeComponent();
MainPage = new MainPage();
}
MainPage.xaml:
<StackLayout VerticalOptions="Center" Spacing="50">
<Button Text="Hello" BackgroundColor="Wheat" BorderRadius="20" TextColor="Black">
<Button.Image>
<OnPlatform x:TypeArguments="FileImageSource" Android="icon.png"/>
</Button.Image>
</Button>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Button Text="Left" BackgroundColor="IndianRed" BorderRadius="22" TextColor="Black">
<Button.Image>
<OnPlatform x:TypeArguments="FileImageSource" Android="icon.png"/>
</Button.Image>
</Button>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Button Text="Right" BackgroundColor="IndianRed" BorderRadius="22" TextColor="Black">
<Button.Image>
<OnPlatform x:TypeArguments="FileImageSource" Android="icon.png"/>
</Button.Image>
</Button>
</StackLayout>
</StackLayout>
</StackLayout>
我加载了默认 icon.png 并检查了 hdpi(72x72)、mdpi(48x48)、xhdpi(96x96)、xxhdpi(144x144)、xxxhdpi(192x192) 的尺寸是否正确。
我看到按钮位置正确,里面有文字但没有图像。有什么问题?
【问题讨论】: