【问题标题】:xamarin.forms set backgroundimage for page from file in androidxamarin.forms 从 android 中的文件为页面设置背景图像
【发布时间】:2016-08-22 16:50:43
【问题描述】:

我有一个在运行时创建的图像文件。

我想将其设置为 ContentPage 的 backgroundImage(在 android 项目中)

我尝试将文件的路径设置为 BackgroundImage 属性,但它不起作用。

有办法吗?

我不能把它作为资源,因为我是在运行时创建的

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    将您的页面放入Grid,其中第一个元素是Image,然后将该图像Source 设置为您的流,例如:

        Image bgImage = new Image
        {
            Source = ImageSource.FromStream(() => { return new MemoryStream(buffer); });
        }
    
        Grid mainGrid = new Grid
        {
            Children = {bgImage,yourContent}
        };
        yourPage.Content= mainGrid;
    

    【讨论】:

    • 无法回答,因为您提出了解决方法。 BackgroundImage 建议在页面背景上显示图像。它适用于 Ios 和 UWP (Windows 10)。不适用于 Android。
    • 亲爱的 Nuri,如果您的图像格式正确,它将适用于所有平台,并且应该有解决方法,因为您无法使用当前结构。
    【解决方案2】:

    我认为文档已经过时了。因为目标 Android 拥有不止一种资源。 作为 /drawable-hdpi /drawable-xhdpi 等等

    因此,您应该为所有文件夹添加图像,因为它适用于设备。它有效。

    *但我认为 Xamarin.Forms 的主要问题 因为当系统找不到特殊分辨率时,可绘制文件夹必须默认图像源必须从默认文件夹中选择... *

    【讨论】:

      猜你喜欢
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多