【问题标题】:Xamarin forms: Android image type and path for onplatform when using ffimageloadingXamarin 表单:使用 ffimageloading 时 onplatform 的 Android 图像类型和路径
【发布时间】:2018-04-16 23:51:14
【问题描述】:

使用 Xamarin Forms 和 NuGet FFImageloading 插件,我想在我的 XAML 代码中指定操作系统特定的图像路径,如下所示:

     <ffimageloading:CachedImage DownsampleToViewSize="False" Aspect="AspectFill">

        <ffimageloading:CachedImage.Source>
           <OnPlatform x:TypeArguments="ImageSource"   
              iOS="MyProject.iOS.Resources.header_background.png" 

   Android="MyProject.Droid.Resources.Drawable.header_background.png" />
        </ffimageloading:CachedImage.Source>

     </ffimageloading:CachedImage>

iOS 映像声明为BundleResource,而Android 映像声明为AndroidResource。在 iOS 上,图像加载正常,但在 Android 上,我不断收到此错误:

资源目录名无效:Error APT0000: obj/Debug/res/myproject.droid.resources.drawable.header_background.png (APT0000) (MyProject.Android)

怎么了?图像的构建类型错误?没看懂。

【问题讨论】:

    标签: xamarin.forms ffimageloading


    【解决方案1】:

    Xamarin.Forms 中的图像源基于默认路径,这比直接文件路径更有优势。

    将图片放入

    1. Android - /Resources/drawable
    2. iOS - /Resources 或作为资产
    3. UWP - 根项目文件夹

    然后您只需通过名称 header_background.png 引用它。

    这有额外的好处,你可以为 iOS 放置 @2x 或更大的图像,在 Android 中将图像放置在 drawable-hdpi 或其他类型的可绘制文件夹中,操作系统将确定最合适的获取。

    【讨论】:

      【解决方案2】:

      两个平台的文件名相同 header_background.png.. 所以设置 Source="header_background.png" 属性将在适当的资源中自动从 droid 和 ios 项目中读取。

      【讨论】:

        猜你喜欢
        • 2018-08-17
        • 1970-01-01
        • 2017-12-14
        • 1970-01-01
        • 2021-06-05
        • 1970-01-01
        • 2018-07-12
        • 1970-01-01
        • 2017-08-03
        相关资源
        最近更新 更多