2016-08-12 93 views
2

我使用此代碼,以顯示與URL圖像顯示圖像

的.xaml

<?xml version="1.0" encoding="UTF-8"?> 
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LandAHand.VolunteerView"> 
     <ContentPage.Content> 
      <AbsoluteLayout BackgroundColor="Maroon"> 
       <Image x:Name="backgroundImage" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/> 
      </AbsoluteLayout> 
     </ContentPage.Content> 
    </ContentPage> 

的.cs

using System; 
using System.Collections.Generic; 

using Xamarin.Forms; 

namespace LandAHand 
{ 
    public partial class VolunteerView : ContentPage 
    { 
     public VolunteerView() 
     { 
      InitializeComponent(); 
      backgroundImage.Source = new UriImageSource 
      { 
       Uri = new Uri("https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg"), 
       CachingEnabled = true, 
       CacheValidity = new TimeSpan(5, 0, 0, 0) 
      }; 
     } 
    } 
} 

該代碼已成功與iOS工作,但不適用於android。

+0

我剛測試這個,它的工作原理。 –

回答

1

那麼你可以用XAML中做這個事情更容易只是讓你的XAML這樣

<Image x:Name="backgroundImage" Source="https://s9.postimg.org/aq1jt3fu7/handshake_87122244_std.jpg" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/> 

並刪除相關的代碼後面的代碼。兌現是默認啓用24小時

+0

在IOS設備上工作正常,但在Android設備上不能工作 – suthar

+0

如果將它放入堆棧佈局而不是絕對地址,那麼該怎麼辦?並在不同的設備上嘗試它 – BraveHeart