【问题标题】:Image in Xamarin formsXamarin 形式的图像
【发布时间】:2021-10-05 19:26:29
【问题描述】:

图像对象(Xamarin 表单)上不显示某些图像,尤其是使用手机相机拍摄的图像。 显示图像有什么规则吗?我在 Microsoft 文档中找不到任何可以帮助我的东西!

例如,我放了四个图像来显示。显示第一张图片,但不显示接下来的 3 张图片!

如果有从事该领域工作的人提供指导,我将不胜感激

ِDisplayed

Not Displayed

Not Displayed

Not Displayed

 <Image
 Source="Moto.jpg"
 VerticalOptions="CenterAndExpand"
 HorizontalOptions="CenterAndExpand" />

【问题讨论】:

  • 显示您的代码。
  • 恐怕您需要向我们提供更多信息,您只是在使用图像控件,还是在尝试做轮播?这种事情并为我们提供您的代码示例将使我们能够更快地为您提供帮助。
  • 您使用的是相对图像路径。您的相机图片存储在其他文件夹中,例如 Android 中的 /DCIM/Camera/...。要访问该路径,您需要获得许可。
  • “我放了四张图片来显示。第一张图片显示,但接下来的 3 张图片没有显示!” 要准确了解您所做的:1)制作 XAML页面尽可能简单,但仍然存在错误。 2) 添加以质疑该(简单)页面的 整个 .xaml 和 .xaml.cs 源。

标签: image xamarin xamarin.forms


【解决方案1】:

我把四张图片放在项目(iOS/Android)中,它按预期显示。


这里有一些建议给你

  1. 将图像文件放在正确的文件夹中。

    iOS:Resources 文件夹或Asset Catalogs。

    Android:Resources/drawable 文件夹。

    请参阅https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images。

  2. 检查 xaml 中的 image name,它应该与文件夹中的名称相对应(区分大小写)。

  3. 避免图像控件相互重叠。


//this is my test code 
 <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Image Source="a.jpg" />
        <Image Source="b.jpg" Grid.Column="0" Grid.Row="1"/>
        <Image Source="c.jpg" Grid.Column="1" Grid.Row="0"/>
        <Image Source="d.jpg" Grid.Column="1" Grid.Row="1"/>
    </Grid>

【讨论】:

    【解决方案2】:

    我发现了问题:

    图像属性 -> 构建操作 -> “Android 资源”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      相关资源
      最近更新 更多