xaml - 为什么 Android 对待下载的图像与嵌入的图像不同
问题描述
我有 3 张图片。它们都是圆形的(实际上是带有透明背景的方形),并且都是 3 个完全相同的大小。
我希望以下 xaml 生成 3 个外观相似的图像,由于 AspectFill,所有图像都被拉伸到容器的最大值,保持它们的纵横比。
这适用于 UWP,但在 Android 上,只有第一个图像似乎想听我的计划。我能找到的唯一区别是第一个图像是嵌入式资源,而其他图像是下载的。(它们不是直接从url显示,而是先存储在本地)
如果我只显示下载的图像,它们都显示为“小”。如果我只显示嵌入的图像,它们都显示为“大”。
在我看来,Android 在应用 Aspect 时处理下载的图像与嵌入图像不同,但我不知道为什么。
<ScrollView Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Grid>
<StackLayout x:Name="NarrationsStackLayout" BindableLayout.ItemsSource="{Binding Narrations}" Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="Fill">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Image Source="{Binding NarrationImage}" Aspect="AspectFill" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" BackgroundColor="Green" >
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Image.GestureRecognizers>
</Image>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</Grid>
</ScrollView>
什么可能导致这种行为?
解决方案
在 Leo Zhu 的建议下,我有一个有效的解决方法来解决我的问题,但我仍然对原因感到困惑。
<StackLayout x:Name="NarrationsStackLayout" BindableLayout.ItemsSource="{Binding Narrations}" Orientation="Horizontal" HorizontalOptions="CenterAndExpand" VerticalOptions="Fill" Margin="0" Padding="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Image Source="{Binding NarrationImage}" Aspect="AspectFill" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" BackgroundColor="Green"
HeightRequest="{Binding Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackLayout }}, Path=Height}"
WidthRequest="{Binding Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackLayout }}, Path=Height}">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Image.GestureRecognizers>
</Image>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
推荐阅读
- ios - 如何仅设置苹果徽标图像以使用苹果按钮登录
- python-3.x - 为什么我的 cplex 约束使我的模型变慢?
- python - 将用户会话数据导入其他 django 应用程序
- python - groupby 和 agg by 多列错误
- python - 有没有办法从python中两个端点之间的日志文件中打印数据
- api - 是否有可能验证 POSTMAN 请求字段是否强制
- r - 如何比较R中的两行日期并转换为一行
- php - 在 PHP 中检索和显示登录信息
- r - 删除 rowr 包后,如何创建长度不等的数据框?
- python - CX_Oracle - 将特定模式中的 Oracle 数据导入 Pandas 数据框