2016-06-29 4 views
0

Ich habe einige Arten von Bild in RessourcenWie in Xamarin Forms-Projekt verschiedene Größen der BackgroundImage-Eigenschaft für Page verwenden?

- 320 x 480 login-background.png 
- 640 x 960 [email protected] 
- 640 x 1136 [email protected] 
- 750 x 1334 [email protected] 
hinzugefügt

solution explorer pic

Dann habe ich Background Eigenschaft in XAML wie "Bild/login-Hintergrund" xaml page pic

Aber es immer noch gefüllt funktioniert nicht. Sowohl das Gerät als auch der Simulator rendern 320 x 480.

Antwort

2

Xaml erkennt die -568h oder @2x e.t.c für iOS nicht. Es wählt das Bild aus, das dem genauen Namen ohne Erweiterung entspricht. Es funktioniert auf Android, da alle Bilder denselben Namen haben und die Auflösungsordner unterschiedlich sind.

Als Workaround können Sie Bilder aus dem C# -Code festlegen, indem Sie die Höhe/Breite durch Überschreiben der OnSizeAllocated-Methode betrachten.

protected override void OnSizeAllocated(double width, double height) 
{ 
    base.OnSizeAllocated(width, height); 
    string BackGroundImgName = "myimage"; 
    Device.OnPlatform(iOS:() => 
    { 
     if (width >= 414) 
      // iPhone 6 Plus 
      this.BackgroundImage = BackGroundImgName + "[email protected]"; 
     else if (width >= 375) 
      // iPhone 6 
      this.BackgroundImage = BackGroundImgName + "[email protected]"; 
     else if (width >= 320 && height >= 500) 
      // iPhone 5 
      this.BackgroundImage = BackGroundImgName + "[email protected]"; 
     else if (width >= 320) 
      // iPhone 4 
      this.BackgroundImage = BackGroundImgName + "@2x.png"; 
     else 
      this.BackgroundImage = BackGroundImgName + ".png"; 
    }, 
    Android:() => { this.BackgroundImage = BackGroundImgName + ".png"; } 
    ); 
}